如何使用 Stimulsoft Reports 在客户端而不是服务器中保存导出的报告

How to save an exported report in client not server using Stimulsoft Reports

我的 ASP.Net 网络应用程序中有一份 Stimulsoft 报告。

我想使用此 C# 代码导出它。

report.ExportDocument(StiExportFormat.Excel2007, "d:\ExportedFile.xlsx", exportSettings);

但是此代码将报告导出到服务器,而不是客户端。

如何将报告保存到客户的存储空间?

我自己找到了答案。

我应该将导出的数据写入 MemoryStream,而不是文件。然后将 MemoryStream 发送到 Current HttpContext 的 Response。 通过这种方式,将打开一个下载对话框并询问客户端存储上的下载路径。

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 class。 它returns 将报告导出为指定格式。

StiReportResponse.ResponseAsPdf(this, report);
StiReportResponse.ResponseAsExcel2007(this, report);

您还想在 Stimulsoft Programming Manual 中获取更多信息。

您可以在报表上使用 ExportDocument() 方法

MemoryStream st = new MemoryStream();
report.ExportDocument(StiExportFormat.Excel2007, st);