2011-09-08 107 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); 
相關問題