首页 > 解决方案 > 如何删除尾随零?

问题描述

jxl.write.WritableCellFormat.WritableCellFormat在下载 Excel 时使用。

Excel下载很好。

但是 cellFormatStyle 并没有按照我想要的方式出现。

- 现在问题 1 -> 1.000 0.003 -> 0.003

-我想要 1 -> 1 0.003 -> 0.003

我应该怎么办??请帮助我。

下面是问题的代码。

NumberFormat numberFormat = new NumberFormat("0.###")

WritableCellFormat cellStyle = new WritableCellFormat(numberFormat);

标签: javaexcel

解决方案


您可以检查右 4 个字符是否小于零,如果不是,则更改数字格式。因此,假设您的数据在单元格 A1 中:

If Right(Range("A1"), 4) < 1 Then
Else
'This means it is not < 1 and therefore not a decimal
Range("A1").NumberFormat = "0"
End If

推荐阅读