无法使用POI应用特定的单元格数据格式

时间:2015-04-20 11:17:32

标签: java excel apache apache-poi

我正在使用Apache POI将数据写入Excel。我正在尝试向Excel单元格写一个大的十进制数字,我正在使用以下方法:

#1:

CellStyle style= wb.createCellStyle();
style.setDataFormat(df.getFormat("000.0000000"));

#2:

CellStyle style= wb.createCellStyle();
HSSFCreationHelper createHelper = wb.getCreationHelper();
style.setDataFormat(
    createHelper.createDataFormat().getFormat("000.0000000"));

以下是所需格式:

0.0000000   ---> 000.0000000
1.0000000   ---> 001.0000000
10.0000000  ---> 010.0000000
101.0068721 ---> 101.0068721
111.0034360 ---> 111.0034360
010.0034526 ---> 010.0034526
100.1452672 ---> 100.1452672

但我最终使用以上数据格式输出以下输出:

0.0000000   ---> 000.0000000
1.0000000   ---> 000.0000000
10.0000000  ---> 000.0000000
101.0068721 ---> 000.0068721
111.0034360 ---> 000.0000000
010.0034526 ---> 000.0034526
100.1452672 ---> 000.1452672 

什么是正确的数据格式?

1 个答案:

答案 0 :(得分:0)

您应该在小数点前使用“”代替“ 0 ”。因此,您的数据格式应为“ ## 0.0000000 ”。

相关问题