报表导出Excel分页错乱
我打印报表预览后是2页,但是导出EXCEL之后,第一页和第二页没有连接上,并且最后一列错位了
请求帮忙看下,文件在附件中,谢谢。
您好!您的意思是预览的时候正常,但是导出Excel后就出现错乱是吧!
如果是这样,请问您的报表是Winform形式还是Webviewer形式。如果是Winform的话,您换这种导出办法试试。GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyExcel");
outputDirectory.Create();
// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
// Set the rendering extension and render the report.
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));
// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;
reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
如果是webViewer的形式,您把能反映您问题的代码发过来我给看看具体是什么问题 /// <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的代码段 麻烦帮忙看下谢谢
要不您最好把可以重现您问题的demo发过来,我这边给看看。看您发的这段代码,看起来好像没错。用的也是我发给您的导出Excel的方法 这边没法做demo 我用EXCEL 把数据导给你行吗?
可以的!您把数据和报表模板发过来。我这边做个验证,看看会不会出现您反馈的问题。还有记得备注说明AR的版本 AR 10
模板在一楼有 这边是数据 您好!您现在遇到的问题是,当预览的结果为多页时,导出的Excel就出现分页的情况。这种问题的出现,主要是由于导出Excel时的一个属性的设置,在系统的默认情况下它的属性默认为true,然后导出的结果就会随着预览的结果进行分页。
具体设置如下:
如果直接在报表上设计器上预览,设置如下:
后台代码:
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;
<b> excelSetting.MultiSheet = false;</b>
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;
_document.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
我原来代码就已经设置过了不允许多页打印了,但是还是这样 还有我怀疑是合并单元格的问题打印的时候,行会自动合并
但是有时候不会,是不是这边的原因,因为最后一列也是自动合并的
页:
[1]
2