问题描述
我制作了一个excel报告,其中包含一些Double
类型TextFields
和数字格式模式##0.#
I made an excel report, which contains some Double
type TextFields
with number format pattern ##0.#
在OpenOffice中,这些单元格的格式正确(正是我所需要的格式)
In OpenOffice, these cells are formatted correctly (Which is exactly what I need)
- 1.56-> 1.6
- 0.0-> 0
但是,当我使用Microsoft Excel打开报表时,小数点并没有像我期望的那样消失.
However, when I opened report with Microsoft Excel, the decimal point did not disappear like I excpected.
- 1.56-> 1.6
- 0.0-> 0.
经过一番搜索,我在Excel中找到了有关数字格式的帖子.
After some search, I found a post about number format in Excel.
我按照帖子的建议尝试了[=0]0;.#
.但是Excel抱怨我的手机号格式损坏.
I tried [=0]0;.#
instead as the post suggested. But Excel complain about about my cell number format are broken.
我的问题是:我应该在JasperReport中使用哪种模式,以便Excel不会显示尾随的小数点?
My question is : What pattern should I use in JasperReport, so Excel won't show the trailing decimal point ?
更新:我只是发现链接中描述的模式无法解决所有情况,它仅匹配0,而不匹配1.0、2.0 ...等等.
UPDATE : I just find out the pattern described in link dose not solve all cases, it match only 0, not 1.0, 2.0... etc.
推荐答案
作为解决方法,您可以将以下代码粘贴到字段中:
As workaround you may paste in field this code:
new DecimalFormat("0.##").format($F{bigdecValue})
因此,如果thera为Trailinig零,则对xls的处理将不带逗号.
So, processing for xls will be without comma if thera are trailinig zeros.
这篇关于使用JasperReport在Excel中遇到麻烦的格式小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!