Export to Excel format: cell type “general” and number turn into scientific notation

有些话、适合烂在心里 提交于 2020-01-06 14:27:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!