我正在尝试使用 apache poi 将 xls 和 xlsx 文件转换为 csv,但遇到了某种问题,我不知道如何解决。基本上,当单元格包含大数字时,代码会将该数字输出为奇怪的格式。
for (int cn = 0; cn < lastColumn; cn++) {
Cell c = r.getCell(cn);
if (c == null) {
sb.append("|");
} else {
sb.append(c + "|");
}
}
示例:
电子表格在一个单元格中包含此数字:84172870494
输出是这样的:8.4172870494E10
所需输出:84172870494
基本上它添加了一个“。”末尾是“E%”。
最佳答案
您必须定义格式才能告诉 POI 如何解析数据。
DataFormat format = wb.createDataFormat();
CellStyle style = wb.createCellStyle();
style.setDataFormat(format.getFormat("#.###############"));
cell.setCellStyle(style);
并检查 xls 格式:
https://poi.apache.org/components/spreadsheet/quick-guide.html#DataFormats https://support.microsoft.com/en-us/help/264372/how-to-control-and-understand-settings-in-the-format-cells-dialog-box
关于java - Apache POI 奇怪的数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56528030/