1、 首先导出Excel出现多页的问题,即当报表预览的时候有多页,导出Excel的时候就会有多个sheet
如图:
这是由于导出Excel的时候有一个MultiSheet的属性,在最开始的时候默认系统默认为true
只需要设置该属性为false 就可以解决该问题了。
代码实现:
private void tsbExcel_Click(object sender, EventArgs e) { GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"123.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyExcel"); outputDirectory.Create(); GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings(); excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls; excelSetting.MultiSheet = false; //核心代码 GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting; GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name)); outputProvider.OverwriteOutputFile = false; reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings()); }
2、 Excel分页合并处出现一点点错乱的问题
如图:
这也是属性设置的问题,在默认情况下Pagination的属性为true 只需要把该属性设置为false就行