Crystal reports 如何在crystal report viewer中设置默认导出名称
在ASP.NET页面上,当用户从Crystal report Viewer(CRV)查看报告时,他们可以将报告导出(如导出到PDF)。导出的默认文件名是CRV的ID 我想将默认名称设置为基于报表参数的名称。(如“2008年销售额”)Crystal reports 如何在crystal report viewer中设置默认导出名称,crystal-reports,Crystal Reports,在ASP.NET页面上,当用户从Crystal report Viewer(CRV)查看报告时,他们可以将报告导出(如导出到PDF)。导出的默认文件名是CRV的ID 我想将默认名称设置为基于报表参数的名称。(如“2008年销售额”) 我知道我可以在页面上添加一个链接,然后我可以编写一个解决方案,在代码中生成PDF并将其传输到浏览器,但是我希望有一种方法可以在Crystal Reports中实现这一特性。如果您使用Visual Studio 2008创建报表,您可以编辑创建的ReportClass
我知道我可以在页面上添加一个链接,然后我可以编写一个解决方案,在代码中生成PDF并将其传输到浏览器,但是我希望有一种方法可以在Crystal Reports中实现这一特性。如果您使用Visual Studio 2008创建报表,您可以编辑创建的ReportClass以添加DefaultName属性。本来就有一个ReportExporter类可以代替ReportViewer类,但它不再受支持。第三部分也有相似之处
// You could pass the parameters to the web page
// where you have theCrystalReportViewer control
protected void Page_Load(object sender, EventArgs e)
{
string reportId = Request["rid"];
string reportTitle = Request["rtitle"];
ReportDocument reportDocument = HttpContext.Current.Session[reportId] as ReportDocument;
this.CommonCrystalReportViewer.ReportSource = reportDocument;
this.CommonCrystalReportViewer.DataBind();
// Set the default export file name for the report.
this.CommonCrystalReportViewer.ID = reportTitle;
}
我使用以下代码示例:
从报告中获取参数值(如果您尚未从会话、查询字符串或其他地方获取参数值)
需要使用报表名称导出
string myReportName = "sales for " + myParamValue.ToString() + ".pdf";
try
{
reportDocument.ExportToHttpResponse(
ExportFormatType.PortableDocFormat
,Response, true, myReportName);
}
catch (System.Threading.ThreadAbortException)
{
//System.Threading.ThreadAbortException is thrown
//because, Response.End is called internally in ExportToHttpResponse method:
}
必须在
Page\u Init
函数中更改reportViewer
id
,否则将无法工作。我相信这是报表上的DocumentName属性
string myReportName = "sales for " + myParamValue.ToString() + ".pdf";
try
{
reportDocument.ExportToHttpResponse(
ExportFormatType.PortableDocFormat
,Response, true, myReportName);
}
catch (System.Threading.ThreadAbortException)
{
//System.Threading.ThreadAbortException is thrown
//because, Response.End is called internally in ExportToHttpResponse method:
}
protected void Page_Init(object sender, EventArgs e) {
...
// Set the default export file name for the report.
this.mainReportViewer.ID = reportTitle;
...
}