2016-01-19 27 views

回答

0

我自己找到了答案。

我應該將導出的數據寫入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(); 
1

您應該使用StiReportResponse類。 它返回導出爲指定格式的報告。

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

你冷得到Stimulsoft Programming Manual的更多信息。

2

您可以在報表中使用ExportDocument()方法

MemoryStream st = new MemoryStream(); 
report.ExportDocument(StiExportFormat.Excel2007, st); 
相關問題