我这边报表原来是先进行预览在进行另存为Excel的,现在我直接不预览直接另存为excel报错
- NameValueCollection filter = paras.ToNameValueCollection();
- ActiveReportClass AReportViewer = new ActiveReportClass();
- AReportViewer.isFormarPrint = false;
- AReportViewer.Dr = CacheManager.GetCache<DataRow>(filter["drKey"].Kstring());
- AReportViewer.ReportPath = AReportViewer.Dr["reportpath"].Kstring();
- AReportViewer.ReportName = AReportViewer.Dr["bbname"].Kstring();
- AReportViewer.Filter = System.Web.HttpUtility.ParseQueryString(paras);
- //AReportViewer.Filter = CacheManager.GetCache<string>(paras).ToNameValueCollection();
- //区域报表显示
- if (AReportViewer.ReportPath.Contains("rpx"))
- {
- AReportViewer.ReportViewer = AReportViewer.GetSectionReportView(this.ItemData, AReportViewer.ReportPath);
- AReportViewer.ReportType = "rpx";
- }
- else
- {
- //获取页面报表对象
- AReportViewer.ReportViewer = AReportViewer.GetPageReportView_NForPrint(this.ItemData, AReportViewer.ReportPath);
- AReportViewer.ReportType = "rdlx";
- if (AReportViewer.isFormarPrint)
- {
- //获取套打时页面报表对象,即没有底图的情况,用于套打按钮使用
- AReportViewer.ForPrintViewer = AReportViewer.GetPageReportView_ForPrint(this.ItemData, AReportViewer.ReportPath);
- }
- }
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- ms = AReportViewer.GetExportReportStream("type=" + filter["type"].Kstring(), AReportViewer.ReportViewer, AReportViewer.ReportType);
- DoSaveFile(AReportViewer.ContentType, AReportViewer.FileName, ms);
复制代码- #region 获取excel数据流
- /// <summary>
- /// 获取excel文件数据流
- /// </summary>
- /// <param name="excelType">excel类型,xls或者xlsx</param>
- /// <returns>返回excel文件数据流</returns>
- private MemoryStream GetExcleMemoryStream(string excelType,Boolean excelmethod=false)
- {
- Boolean newexeclmethod = excelmethod;
- if (this.reportType == "rpx")
- newexeclmethod = false;
- MemoryStream excelMemoryStream = new MemoryStream();
- if (!newexeclmethod)
- {
- GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
- XlsExport.UseCellMerging = true;
- #region excel类型
- if (excelType == "XLS")
- {
- XlsExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xls97Plus;
- }
- else
- {
- XlsExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
- }
- #endregion
- #region 导出数据流
- if (this.ReportType == "rpx")
- {
- SectionReport sectionReport = (SectionReport)this.ReportViewer;
- sectionReport.Run();
- XlsExport.Export(sectionReport.Document, excelMemoryStream);
- //转为文件的方法为pdfExport.Export(sectionReport.Document, 地址路径);
- }
- else
- {
- PageReport pagereport = (PageReport)this.ReportViewer;
- //GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pagereport);
- //XlsExport.Export(pageDocument, excelMemoryStream);
- XlsExport.Export(pagereport.Document, excelMemoryStream);
- }
- #endregion
- }
- else
- {
- PageReport pagereport = (PageReport)this.ReportViewer;
- //GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(pagereport);
- GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = pagereport.Document;
- GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings XlsExport = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
- #region excel类型
- if (excelType == "XLS")
- {
- XlsExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
- }
- else
- {
- XlsExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx;
- }
- #endregion
- XlsExport.MultiSheet = false;
- XlsExport.Pagination = false;
- GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = XlsExport;
- 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, XlsExport.GetSettings());
- outputProvider.GetPrimaryStream().OpenStream().CopyTo(excelMemoryStream);
- }
- return excelMemoryStream;
- }
复制代码
运行到这一行就抛异常
|