2011-09-08 25 views
5

Tengo un archivo jasper que exporto a PDF y Excel ahora estoy usando solo un jaspe Quiero que el informe PDF exportado sea "isIgnorePagination = '' true" y para el informe de Excel debería ser "isIgnorePagination = 'false' "¿?"Cómo establecer dinámicamente isIgnorePagination en el informe de jaspe?

¿Cómo establecer desde código java?

+1

Puede pasar esta propiedad a través del parámetro JRParameter.IS_IGNORE_PAGINATION (en caso de que utilice el método JasperFillManager.fillReport) –

+0

Hola Alex, lo que quiero es exactamente cómo configurar "isIgnorePagination = 'true'" para PDF y "isIgnorePagination = 'false'" para excel? – HariKanna

+2

Desde el código java puede establecer JRParameter.IS_IGNORE_PAGINATION y establecer el formato de exportación como desee –

Respuesta

5

Deberá saber en tiempo de ejecución si está exportando a Excel o PDF, lo cual debe saber.

Sólo como ejemplo:

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

He encontrado una solución para esto.

mi código es:

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

Según JasperReports sample reference:

para diversos fines esta bandera [isIgnorePagination en jrxml] puede ser anulado en el informe tiempo de llenado con el programa opcional incorporado IS_IGNORE_PAGINATION parámetro.

Así que el código debe ser algo como esto:

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); 
Cuestiones relacionadas