jasper not formatting excel data types

2019-05-10 09:32发布

问题:

I have a Jasper Report which seems to be exporting fine in all formats except Excel.

The below sample is of a column that should be formatted as currency but shows incorrectly.

Here are the jasper properties i'm using...

out = new FileOutputStream(file);
JExcelApiExporter exporterXLS = new JExcelApiExporter();

exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.CREATE_CUSTOM_PALETTE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, out);

exporterXLS.exportReport();

I've tried both Jasper 4.0 and 4.5. I think it has to do with a dependency but i'm not sure.

回答1:

You can try to add net.sf.jasperreports.export.xls.pattern property for your textField element in jrxml file.

You can find the sample here.



回答2:

fixed!

Instead of using the JRXlsExporterParameter class i used the parameters as follows and it worked!

    jasperPrint.setProperty("net.sf.jasperreports.export.xls.create.custom.palette", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.one.page.per.sheet", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.remove.empty.space.between.rows", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.remove.empty.space.between.columns", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.white.page.background", "true");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.detect.cell.type", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.size.fix.enabled", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.ignore.graphics", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.collapse.row.span", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.ignore.cell.border", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.ignore.cell.background", "false");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.max.rows.per.sheet", "0");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.wrap.text", "true");
    jasperPrint.setProperty("net.sf.jasperreports.export.xls.use.timezone", "false");