你好导出Excel的代码,因为你使用的是动态数据源绑定,所以需要这样先加载动态数据源- protected void Button1_Click(object sender, EventArgs e)
- {
- GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
复制代码
protected void Button1_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
rpt.Document.LocateDataSource += new LocateDataSourceEventHandler(LocateData);
GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt);
// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx;
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings());
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
System.IO.MemoryStream ms = new System.IO.MemoryStream();
//outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
|