using DataDynamics.ActiveReports.Export.Xls;
using DataDynamics.ActiveReports.Export.Pdf;
如果你想导出为其他的格式,别忘了引入对应的命名空间哦.
下边就是最关键的数据导出代码了:
//导出为pdf文件
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
AdverReport rpt = new AdverReport();
int nADCount = 0;
rpt.DataSource = ADS.GetAdve_ADS_List((int)Session[CoFunction.SESSION_ADVER], ref nADCount);
rpt.Run();
PdfExport pdfExport1 = new PdfExport();
pdfExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=MyExport.pdf");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
简单说明一下:第一行,我们创建一个内存流,第二行声明一个报表文件类的对象,然后指定报表的数据源,接着就是声明一个PdfExport类的对象,然后就是导出的代码了,应该不难理解吧?
导出为excel的代码类似:
//导出为excel文件
System.IO.MemoryStream m_stream = new System.IO.MemoryStream();
AdverReport rpt = new AdverReport();
rpt.CompanyName = ViewState["CompanyName"].ToString();
int nADCount = 0;
rpt.DataSource = ADS.GetAdve_ADS_List((int)Session[CoFunction.SESSION_ADVER], ref nADCount);
rpt.Run();
XlsExport xlsExport1 = new XlsExport();
xlsExport1.MinColumnWidth = (float)0.5;
xlsExport1.Export(rpt.Document, m_stream);
m_stream.Position = 0;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=MyExport.xls");
Response.BinaryWrite(m_stream.ToArray());
Response.End();
没什么好说的了,另外几种格式文件的导出应该也差不多,自己试试吧:)