简体   繁体   English

导出为Excel格式:“常规”单元格类型和数字变为科学计数法

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

I have created a Jrxml to generate an excel output. 我创建了一个Jrxml来生成一个excel输出。 The textfield of data type "String" in iReport is displayed with cell format as 'General' in the generated excel output. iReport中数据类型为“ String”的文本字段在生成的excel输出中以单元格格式显示为“常规”。

When Number is greater than 12 digit it turns into scientific notation. 当Number大于12位数字时,它将变成科学计数法。 eg 999999999869 turns to 1E+12 . 例如999999999869变为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. 也尝试过使用pattern="@"pattern="0.00"但它们都不起作用。

JasperReports version used 5.6.1 and org.grails.plugins:jasper 1.11.0 JasperReports版本使用5.6.1和org.grails.plugins:jasper 1.11.0

In most of the cases, adding the following property in report jrxml let excel to detect the cell type: 在大多数情况下,在报表jrxml中添加以下属性可使excel检测单元格类型:

<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. 您会看到,Excel中的默认数字格式为常规,因此您最多只能在一个单元格中显示11位数字,并且此问题适用于Microsoft Office Excel 2010,Excel 2007和Excel2003。获取更高版本的Microsoft Excel会使此问题无效,或者尝试以XLSX格式导出。 Alternatively, you can use other excel readers like Open Office. 或者,您可以使用其他Excel阅读器,例如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. 当您导出到Excel时,您将失去对单元格格式的控制,但作为一种变通办法,尝试在字符前面加上前缀以强制将单元格类型输入文本,请尝试在数字textField前面添加单引号('),例如<![CDATA["'" + $F{LongNumber}]]>或尝试在数字之间插入空格。 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. 否则,最后一个可能的解决方法是从启动报告的Java代码进入Excel。 You can access ROW, COLUMN & CELL level items via poi jar. 您可以通过poi jar访问ROW,COLUMN和CELL级别的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM