我的ASP.Net Web應用程序中有一個Stimulsoft報告。如何使用Stimulsoft報告在客戶端而非服務器中保存導出的報告
我想用這個C#代碼導出它。
report.ExportDocument(StiExportFormat.Excel2007, "d:\\ExportedFile.xlsx", exportSettings);
但該代碼將報告導出到服務器,而不是客戶端。
如何將報告保存到客戶端存儲?
我的ASP.Net Web應用程序中有一個Stimulsoft報告。如何使用Stimulsoft報告在客戶端而非服務器中保存導出的報告
我想用這個C#代碼導出它。
report.ExportDocument(StiExportFormat.Excel2007, "d:\\ExportedFile.xlsx", exportSettings);
但該代碼將報告導出到服務器,而不是客戶端。
如何將報告保存到客戶端存儲?
我自己找到了答案。
我應該將導出的數據寫入MemoryStream而不是文件。然後將MemoryStream發送到當前HttpContext的響應。 通過這種方式,下載對話框將打開並詢問客戶端存儲上的donwload路徑。
MemoryStream memoryStream = new MemoryStream();
renderedReport.ExportDocument(StiExportFormat.Excel2007, memoryStream, exportSettings);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Emad.xlsx");
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
HttpContext.Current.Response.End();
您應該使用StiReportResponse類。 它返回導出爲指定格式的報告。
StiReportResponse.ResponseAsPdf(this, report);
StiReportResponse.ResponseAsExcel2007(this, report);
你冷得到Stimulsoft Programming Manual的更多信息。
您可以在報表中使用ExportDocument()方法
MemoryStream st = new MemoryStream();
report.ExportDocument(StiExportFormat.Excel2007, st);