2011-09-08 95 views
5

我有一个碧玉文件,我出口到PDF和Excel截至现在我只使用一个碧玉我想PDF导出报告应该是“isIgnorePagination =''真正的”和Excel报告应该是“isIgnorePagination ='false' “?如何在jasper报表中动态设置isIgnorePagination?

如何从java代码设置?

+1

您可以通过JRParameter.IS_IGNORE_PAGINATION参数传递这个属性(如果你使用JasperFillManager.fillReport法) –

+0

嗨亚历克斯,我想到底是什么如何为PDF设置“isIgnorePagination ='true'”,为excel设置“isIgnorePagination ='false'”? – HariKanna

+2

从Java代码中,您可以设置JRParameter.IS_IGNORE_PAGINATION并根据需要设置导出格式 –

回答

5

您将需要在运行时知道您是否正在导出到Excel或PDF,您应该知道。

只是作为一个例子:

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(); 
} 
0

我找到解决这个。

我的代码是:

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); 
} 
1

根据JasperReports sample reference

出于各种目的,该标志[isIgnorePagination在JRXML]可以在报告填充时间使用被覆盖了可选的内置IS_IGNORE_PAGINATION参数。

因此,代码应该是这样的:

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); 
相关问题