问题
I have created a Jrxml to generate an excel output. The textfield of data type "String" in iReport is displayed with cell format as 'General' in the generated excel output.
When Number is greater than 12 digit it turns into scientific notation. eg 999999999869 turns to 1E+12
. I need cell format to be either 'text' or 'number'.
I have tried with property
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
But it is not working .
Also tried with pattern="@"
and pattern="0.00"
but none of them works.
JasperReports version used 5.6.1 and org.grails.plugins:jasper 1.11.0
回答1:
In most of the cases, adding the following property in report jrxml let excel to detect the cell type:
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
But looks like you already tried it. In that case, you are left with few dirty solutions that you can try. You see, the default number format in Excel is General therefore you can only display up to 11 digits in a cell and this problem applies to Microsoft Office Excel 2010, Excel 2007 & Excel 2003. Getting a higher version of Microsoft Excel invalidate this issue or try to export in XLSX format. Alternatively, you can use other excel readers like Open Office.
When you export to Excel you lose control of the cell formatting but as a workaround try to prefix a character to force cell type to text, try adding a single quotation mark (') in front of the number textField like <![CDATA["'" + $F{LongNumber}]]>
or try inserting a space(s) between numbers. This is still kind of hacky but might work for you.
Otherwise the last possible fix is to reach into Excel from your java code that launches the report. You can access ROW, COLUMN & CELL level items via poi jar.
来源:https://stackoverflow.com/questions/50214123/export-to-excel-format-cell-type-general-and-number-turn-into-scientific-nota