小编fun*_*her的帖子

使用 Apache-POI 将 Excel 十进制格式解析为 Java BigDecimal

我想在 Apache-POI(XSSF 和 SAX 事件 API)的帮助下导入 XLSX 文件。

由于 Excel 将数字存储为浮点数,因此需要在 java 中将它们格式化回它们在 Excel 中的原始外观。这可以通过读取单元格格式来实现:

String cellStyle = sheetReader.getAttributeValue(null, "s");
if (cellStyle != null) {
  // save the format of the cell for later use.
  int styleIndex = Integer.parseInt(cellStyle);
  XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
  formatIndex = style.getDataFormat();
  formatString = style.getDataFormatString();
  if (formatString == null) {
    // formatString could not be found, so it must be a builtin format.
    formatString = BuiltinFormats.getBuiltinFormat(formatIndex);
  }
}
...
// format the floating-point value
String xlsxValue …
Run Code Online (Sandbox Code Playgroud)

java excel apache-poi

6
推荐指数
1
解决办法
9259
查看次数

标签 统计

apache-poi ×1

excel ×1

java ×1