简体   繁体   English

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

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

I have a Stimulsoft report in my ASP.Net web application. 我的ASP.Net Web应用程序中有一份Stimulsoft报告。

I want to export it using this C# code. 我想使用此C#代码将其导出。

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

but this code exports the report to server, not the client. 但是此代码将报告导出到服务器,而不是客户端。

How can I save the report to client's storage? 如何将报告保存到客户的存储中?

You can use ExportDocument() method on the report 您可以在报表上使用ExportDocument()方法

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

You should use StiReportResponse class. 您应该使用StiReportResponse类。 It returns the report exported to specified format. 它返回导出为指定格式的报告。

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

You cold get more information in the Stimulsoft Programming Manual . 您可以在Stimulsoft编程手册中获得更多信息。

I found the answer by myself. 我自己找到了答案。

I should write the exported data to a MemoryStream, not a file. 我应该将导出的数据写入MemoryStream,而不是文件。 then send the MemoryStream to the Response of Current HttpContext. 然后将MemoryStream发送到当前HttpContext的响应。 In this way a download dialog will be open and ask about donwload path on Client storage. 这样,将打开一个下载对话框,询问客户端存储上的下载路径。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM