下面的方法在aspx下效果还可以,单在cshtml下导出时有错误提示 the data returned by LocateDataSource are null
_reportdata2 = GzxxData.GetRyjbxxs();
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new FileInfo(Server.MapPath("/Reports/ryb/pyrydjb.rdlx")));
((PageReport)(_reportDef)).Document.LocateDataSource += Document_LocateDataSource2;
_reportDef.Run();
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
// Create an output directory
System.IO.MemoryStream ms = new System.IO.MemoryStream();
// 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;
excelSetting.MultiSheet = false;
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();
_reportRuntime.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
//outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
//return File(ms.ToArray(), "application/vnd.ms-excel", Url.Encode("ryjbxx.xlsx"));
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "inline;filename=客户订单.xlsx");
outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End(); |