Java 如何在使用JRParameter.IS_IGNORE_分页时设置Excel打印页边距

Java 如何在使用JRParameter.IS_IGNORE_分页时设置Excel打印页边距,java,jasper-reports,Java,Jasper Reports,使用JR参数时如何设置Excel打印页边距。是否忽略分页 我的Jasper报告包含一个标题和一个包含许多行的表。它是通过设置jr参数创建的。是否忽略分页 params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); return JasperFillManager.fillReport(inputStream, params, new JRBeanCollectionDataSource(myDtoList)); 。。。

使用JR参数时如何设置Excel打印页边距。是否忽略分页

我的Jasper报告包含一个标题和一个包含许多行的表。它是通过设置
jr参数创建的。是否忽略分页

    params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
    return JasperFillManager.fillReport(inputStream, params, new JRBeanCollectionDataSource(myDtoList));
。。。然后通过
JRXlsExporter
导出

结果就是我想要的结果——一张只有一个标题的Excel表格和一张中间没有任何边距或标题的表格

但在打印纸张时,纸张上没有边距。桌子从上边缘开始

在这种情况下,如何设置打印页边距


编辑:在这种特殊情况下,Jasper似乎忽略了
JasperPrint.setTopMargin
JasperPrint.setBottomMargin
的设置。

您需要了解,一旦导出报表,Jasper服务器就不再控制导出的文件。因此,理想情况下,您应该在调用导出之前尝试设置页面边距

您可以使用setLeftMargin、setRightMargin、setTopMargin和setBottomMargin方法在对象上设置页边距(编译对象之前),也可以在对象上设置页边距

JasperPrint的代码示例:

JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, params, new JRBeanCollectionDataSource(myDtoList));
jasperPrint.setLeftMargin(20);
jasperPrint.setRightMargin(20);
jasperPrint.setTopMargin(20);
jasperPrint.setBottomMargin(20);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, stream);
exporter.exportReport();

根据@shertage的评论,以下是解决方案:

SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setPrintPageBottomMargin(20);
configuration.setPrintPageBottomMargin(20);

JRXlsExporter exporterXLS = new JRXlsExporter();
...
exporterXLS.setConfiguration(configuration);
exporterXLS.exportReport();

在这种特殊情况下,要点是,要使用
SimpleXlsReportConfiguration.setPrintPageTopMargin
。。。而不是
JasperPrint.setTopMargin

有一组打印页边距属性可用于Excel导出。请参阅以供参考。@shertage是的,你说得对!我将在对我的问题的单独回答中描述你的解决方案。非常感谢。感谢您的回答-但是当使用参数
IS_IGNORE_PAGINATION
填充报告时,Jasper会忽略这些边距设置。