我只想用PDF,EXCEL,WORD等多种选项导出水晶报表。在这里,我提供了如何实现此功能的代码。
//Page Declaration Section
protected string strQueryString;
protected int intLastPage;
protected int intCurPage;
protected void Page_Init(object sender, System.EventArgs e)
{
strQueryString = Request.QueryString.ToString();
Page.Title = strQueryString.Replace(".rpt", "");
if (!Page.IsPostBack)
{
//Do nothing
}
else if (Session[strQueryString] != null)
{
CrystalReportViewer1.ReportSource = Session[strQueryString];
}
}
protected void lbut_print_Click(object sender, EventArgs e)
{
MPE.Show();
......
reportdocument = new ReportDocument();
SqlConnectionStringBuilder SConn = new SqlConnectionStringBuilder(conString);
reportdocument.Load(Server.MapPath(@"~/Admin/PostHistoryReport.rpt"));
reportdocument.SetDataSource(myDataSet);
reportdocument.DataSourceConnections[0].SetConnection(SConn.DataSource, SConn.InitialCatalog, SConn.UserID, SConn.Password);
Session[strQueryString] = reportdocument;
//Session["SessDoc"] = reportdocument;
CrystalReportViewer1.ReportSource = reportdocument;
}
protected void ImageButton7_Click(object sender, ImageClickEventArgs e)
{
if (DDL_ExportOption.SelectedItem.Value != "-1")
{
ReportDocument crystalReport = (ReportDocument)Session[strQueryString]; // creating object of crystal report
switch (DDL_ExportOption.SelectedItem.Value.ToString())
{
case "1":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "PostRecordDetails");
break;
case "2":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, Response, true, "PostRecordDetails");
break;
case "3":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.WordForWindows, Response, true, "PostRecordDetails");
break;
}
}
}
我怎么得到这个Session[strQueryString]
但是这不会给我输出文件。
请帮帮我......