Search code examples
javajasper-reports

How to set Excel print page margins when using JRParameter.IS_IGNORE_PAGINATION


How to set Excel print page margins when using JRParameter.IS_IGNORE_PAGINATION?

My Jasper-Report contains a header and a table with many rows. It is created with the setting JRParameter.IS_IGNORE_PAGINATION ...

    params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
    return JasperFillManager.fillReport(inputStream, params, new JRBeanCollectionDataSource(myDtoList));

... and then exported via JRXlsExporter.

The result is how I want it - an Excel sheet with one heading and a table without any margins or headings in between.

But when printing the sheet, there are no margins on the paper. The table starts right at the top edge.

How to set the margins for printing in this case?

EDIT: the setting of JasperPrint.setTopMargin, JasperPrint.setBottomMargin seems to be ignored by Jasper in this special case.


Solution

  • Based on the comment of @shertage, here's the solution:

    SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
    configuration.setPrintPageBottomMargin(20);
    configuration.setPrintPageBottomMargin(20);
    
    JRXlsExporter exporterXLS = new JRXlsExporter();
    ...
    exporterXLS.setConfiguration(configuration);
    exporterXLS.exportReport();
    

    In this special case the point is, to use SimpleXlsReportConfiguration.setPrintPageTopMargin, ... instead of JasperPrint.setTopMargin, ... .