开发者

How to set dynamically isIgnorePagination in jasper report?

开发者 https://www.devze.com 2023-04-03 05:18 出处:网络
I have a jasper file which i export to PDF and E开发者_Go百科xcel as of now i am using only one jasper i want the PDF exported reportshould be \"isIgnorePagination=\'\'true\" and for Excel report shou

I have a jasper file which i export to PDF and E开发者_Go百科xcel as of now i am using only one jasper i want the PDF exported report should be "isIgnorePagination=''true" and for Excel report should be "isIgnorePagination = 'false' "?

How to set from java code?


You will need to know at runtime if you are exporting to Excel or PDF, which you should know.

Just as an example:

public void generateReport(JasperPrint report, boolean isExcel, String saveTo){
  JRExporter exporter = null;
  if (isExcel) {
    exporter = new JRXlsExporter();
    exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
    exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
    //we set the one page per sheet parameter here
    exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
  } else {
    exporter = new JRPdfExporter();     
  }
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);124
  exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, saveTo);
  export.exportReport();
}


According to JasperReports sample reference:

For various purposes this flag [isIgnorePagination in jrxml] can be overriden at report filling time using the optional built-in IS_IGNORE_PAGINATION parameter.

So the code should be something like this:

final Map<String, Object> fillingParameters = new HashMap<>();
if (exportType == ExportType.XLS) {
    fillingParameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
}
final JasperPrint print = JasperFillManager.fillReport(jasperReport, fillingParameters, dataSource);


I found solution for this.

my code is:

paramaters.put("fromDate", fromDate);
paramaters.put("toDate", toDate);
if (!output.equals("pdf"))
{
    paramaters.put("IS_IGNORE_PAGINATION", true);
}
else
    paramaters.put("IS_IGNORE_PAGINATION", false);

JasperPrint jasperPrint = null;
jasperPrint = JasperFillManager.fillReport(CompiledReport,paramaters, connection);

if (output.equals("html")) {
    generateHtmlResponse(response, jasperPrint);
} else if (output.equals("pdf")) {
    generatePdfResponse(response, jasperPrint);
} else if(output.equals("excel")) {
    generateXLResponse(response, jasperPrint);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消