- /// <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;
- 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;
- }
复制代码 这边是转换成EXCEL的代码段 麻烦帮忙看下谢谢
|