水晶报表CrystalReportViewer控件导出xls报错

watermoon1980 2010-08-26 01:45:22
报如下错误:
文件 ****** {5ACF5F0A-7C14-4353-82FD-7AD83B78A35B}.rpt 内出错:无效导出 DLL 或导出格式。

其他格式如word pdf等导出正常

我用的是水晶报表2008 SP3 + Visual Studio 2005 SP1开发做Pull模式的webform 客户端装的运行库是2008 SP3
cs代码如下 请各位方家帮忙分析 谢谢

using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WebReport
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public partial class WebForm1 : System.Web.UI.Page
{
private ReportDocument crReportDocument;
private ParameterFields crParameterFields;
private ParameterField crParameterField;
private ParameterValues crParameterValues;
private ParameterDiscreteValue crParameterDiscreteValue;

protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (!IsPostBack)
{
TxtDate1.Text = DateTime.Now.ToString("yyyy-MM-dd");
TxtDate2.Text = DateTime.Now.ToString("yyyy-MM-dd");

// Initialize Dropdownlist
string reportPath = Server.MapPath("Reports/");
string[] reports = Directory.GetFiles(reportPath, "*.rpt");
IDictionary sortedList = new SortedList();
foreach (string path in reports)
{
crReportDocument = new ReportDocument();
crReportDocument.Load(path);
string reportName = crReportDocument.SummaryInfo.ReportTitle;
if (reportName == null || reportName.Length == 0)
{
int reportNamePrefix = path.LastIndexOf(@"\") + 1;
int reportNameLength = path.Length - reportNamePrefix;
reportName = path.Substring(reportNamePrefix, reportNameLength);
}
sortedList.Add(path, reportName);
crReportDocument = null;
}
reportsList.DataTextField = "value";
reportsList.DataValueField = "key";
reportsList.DataSource = sortedList;
reportsList.DataBind();

ConfigureCrystalReports();

}
else
{
TxtDate1.Text = (string)Session["dateStart"];
TxtDate2.Text = (string)Session["dateEnd"];
crReportDocument = (ReportDocument)Session["reportDocument"];
CrystalReportViewer1.ReportSource = crReportDocument;
}

}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

}
#endregion

protected void Button1_Click(object sender, System.EventArgs e)
{
ConfigureCrystalReports();

Session["reportDocument"] = crReportDocument;
Session["dateStart"] = TxtDate1.Text;
Session["dateEnd"] = TxtDate2.Text;

}

private void ConfigureCrystalReports()
{
//Create an instance of the strongly-typed report object
crReportDocument = new ReportDocument();
crReportDocument.Load(reportsList.SelectedValue);
LogOnDB();
CrystalReportViewer1.ReportSource = crReportDocument;

//Get the collection of parameters from the report
crParameterFields = CrystalReportViewer1.ParameterFieldInfo;

//Access the specified parameter from the collection
crParameterField = crParameterFields["dateStart"];

//Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterField.CurrentValues;
crParameterValues.Clear();

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = Convert.ToDateTime(TxtDate1.Text + " 00:00:00");

//Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);
crParameterDiscreteValue = null;

//Access the specified parameter from the collection
crParameterField = crParameterFields["dateEnd"];

//Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterField.CurrentValues;

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = Convert.ToDateTime(TxtDate2.Text + " 23:59:59");

//Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);

//Set the modified parameters collection back to the viewer so that
//the new parameter information can be used for the report.
CrystalReportViewer1.ParameterFieldInfo = crParameterFields;

}

private void LogOnDB ()
{
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
ConnectionInfo crConnectionInfo;

//从web.config中获取logOnInfo参数信息
string DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
string ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"];
string UserID = System.Configuration.ConfigurationManager.AppSettings["UserID"];
string Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
//string SchemaName = System.Configuration.ConfigurationManager.AppSettings["SchemaName"];

//Set the CrTables object to the Tables collection of the Report's dDtabase
crTables = crReportDocument.Database.Tables;

//Loop through each Table object in the Tables collection and apply the logon info
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
//Set the crConnectionInfo with the current values stored in the report
crConnectionInfo = crTable.LogOnInfo.ConnectionInfo;

//Populate the ConnectionInfo Objects Properties with the appropriate values for
//the ServerName,User ID, Password and DatabaseName.
//However, since Oracle works on Schemas, Crystal Reports does not recognize or store a DatabaseName.
//Therefore, the DatabaseName property must be set to a BLANK string.
crConnectionInfo.DatabaseName = DatabaseName;
crConnectionInfo.ServerName = ServerName;
crConnectionInfo.UserID = UserID;
crConnectionInfo.Password = Password;

crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);

//若要改变方案名字,请按下列格式设定
//crTable.Location = "<new schema name>." + crTable.Name;
//crTable.Location = SchemaName + "." + crTable.Name;
}
}
}
}
...全文
305 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wh_xwm952 2011-10-19
  • 打赏
  • 举报
回复
增加环境变量Path; C:\Program Files\Business Objects\BusinessObjects Enterprise 12.0\win32_x86
可参考https://forumsa.sdn.sap.com/thread.jspa?threadID=1065075&start=0&tstart=0
watermoon1980 2010-09-19
  • 打赏
  • 举报
回复
推一下 路过的各位方家帮忙看下
yourname386 2010-09-07
  • 打赏
  • 举报
回复
版本号:9.1.1.528
yourname386 2010-09-07
  • 打赏
  • 举报
回复
在公司里有几台电脑会出现这种情况而其它的都导出正常,后来老大出手搞定了, 我的是VS2003,下一个 ExportModeller.dll 文件(大小为425K)放到
C:\Program Files\Common Files\Crystal Decisions\XX\bin 下替换原来的文件即可,你可以试一下
watermoon1980 2010-09-07
  • 打赏
  • 举报
回复
感谢yourname386的回复 我也曾怀疑过导出dll的版本问题 为此我把2008推出的每个CRRuntime运行库都升级过 但还是没用
watermoon1980 2010-09-03
  • 打赏
  • 举报
回复
另外我还发现一个奇怪的情况 原先本地调试也是无法成功导出excel 但有次我编辑报表(该报表为第一个所执行的报表)的时候保存了预览数据 结果再次本地调试时全部报表都能成功导出 但其他报表也保存有预览数据的话 依然不行 必须是第一个报表 不知何故 至今未想明白
watermoon1980 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 babyt 的回复:]

一直惦记着这个帖子,因为还没有使用win2008,没有相关经验
刚翻了半个多小时,终于翻到了

http://topic.csdn.net/u/20090722/15/88edd136-9d5b-433d-93a4-b8122d747834.html

看一下上面这个帖子8楼小帆的回复是否可用。
[/Quote]
有劳阿泰版主费心了 我的情况和您提及的问题帖不一样
首先服务器端系统是server 2003不是2008 其次我的报错信息也不是某某组件错误导致
koosen 2010-08-31
  • 打赏
  • 举报
回复
学习了!~
阿泰 2010-08-31
  • 打赏
  • 举报
回复
一直惦记着这个帖子,因为还没有使用win2008,没有相关经验
刚翻了半个多小时,终于翻到了

http://topic.csdn.net/u/20090722/15/88edd136-9d5b-433d-93a4-b8122d747834.html

看一下上面这个帖子8楼小帆的回复是否可用。
watermoon1980 2010-08-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 csui2008 的回复:]

文件 ******

请确认文件夹的读写权限

不行就重装一下,EXCEL
[/Quote]
先感谢csui2008的答复 文件夹读写权限是有的 重装excel?是否能导出某格式文件与服务器端是否安装相应office组件没有关系的
东莞寻香苑 2010-08-27
  • 打赏
  • 举报
回复
文件 ******

请确认文件夹的读写权限

不行就重装一下,EXCEL



watermoon1980 2010-08-27
  • 打赏
  • 举报
回复
请各位方家看下 谢谢
watermoon1980 2010-08-26
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WebReport
{
public partial class WebForm1 : System.Web.UI.Page
{
private ReportDocument crReportDocument;
private ParameterFields crParameterFields;
private ParameterField crParameterField;
private ParameterValues crParameterValues;
private ParameterDiscreteValue crParameterDiscreteValue;

protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);

if (!IsPostBack)
{
TxtDate1.Text = DateTime.Now.ToString("yyyy-MM-dd");
TxtDate2.Text = DateTime.Now.ToString("yyyy-MM-dd");

// Initialize Dropdownlist
string reportPath = Server.MapPath("Reports/");
string[] reports = Directory.GetFiles(reportPath, "*.rpt");
IDictionary sortedList = new SortedList();
foreach (string path in reports)
{
crReportDocument = new ReportDocument();
crReportDocument.Load(path);
string reportName = crReportDocument.SummaryInfo.ReportTitle;
if (reportName == null || reportName.Length == 0)
{
int reportNamePrefix = path.LastIndexOf(@"\") + 1;
int reportNameLength = path.Length - reportNamePrefix;
reportName = path.Substring(reportNamePrefix, reportNameLength);
}
sortedList.Add(path, reportName);
crReportDocument = null;
}
reportsList.DataTextField = "value";
reportsList.DataValueField = "key";
reportsList.DataSource = sortedList;
reportsList.DataBind();

ConfigureCrystalReports();

}
else
{
TxtDate1.Text = (string)Session["dateStart"];
TxtDate2.Text = (string)Session["dateEnd"];
crReportDocument = (ReportDocument)Session["reportDocument"];
CrystalReportViewer1.ReportSource = crReportDocument;
}

}

private void InitializeComponent()
{

}
#endregion

protected void Button1_Click(object sender, System.EventArgs e)
{
ConfigureCrystalReports();

Session["reportDocument"] = crReportDocument;
Session["dateStart"] = TxtDate1.Text;
Session["dateEnd"] = TxtDate2.Text;

}

private void ConfigureCrystalReports()
{
//Create an instance of the strongly-typed report object
crReportDocument = new ReportDocument();
crReportDocument.Load(reportsList.SelectedValue);
LogOnDB();
CrystalReportViewer1.ReportSource = crReportDocument;

//Get the collection of parameters from the report
crParameterFields = CrystalReportViewer1.ParameterFieldInfo;

//Access the specified parameter from the collection
crParameterField = crParameterFields["dateStart"];

//Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterField.CurrentValues;
crParameterValues.Clear();

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = Convert.ToDateTime(TxtDate1.Text + " 00:00:00");

//Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);
crParameterDiscreteValue = null;

//Access the specified parameter from the collection
crParameterField = crParameterFields["dateEnd"];

//Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterField.CurrentValues;

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = Convert.ToDateTime(TxtDate2.Text + " 23:59:59");

//Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);

//Set the modified parameters collection back to the viewer so that
//the new parameter information can be used for the report.
CrystalReportViewer1.ParameterFieldInfo = crParameterFields;

}

private void LogOnDB ()
{
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
ConnectionInfo crConnectionInfo;

//从web.config中获取logOnInfo参数信息
string DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
string ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"];
string UserID = System.Configuration.ConfigurationManager.AppSettings["UserID"];
string Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
//string SchemaName = System.Configuration.ConfigurationManager.AppSettings["SchemaName"];

//Set the CrTables object to the Tables collection of the Report's dDtabase
crTables = crReportDocument.Database.Tables;

//Loop through each Table object in the Tables collection and apply the logon info
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
//Set the crConnectionInfo with the current values stored in the report
crConnectionInfo = crTable.LogOnInfo.ConnectionInfo;

crConnectionInfo.DatabaseName = DatabaseName;
crConnectionInfo.ServerName = ServerName;
crConnectionInfo.UserID = UserID;
crConnectionInfo.Password = Password;

crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);

//若要改变方案名字,请按下列格式设定
//crTable.Location = "<new schema name>." + crTable.Name;
//crTable.Location = SchemaName + "." + crTable.Name;
}
}
}
}

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧