如图,aspose得到的值和MS office365显示的值不同:
20250318-174129.jpg (90.3 KB)
aspose的结果为:上午0时00分
MS office365的结果为:上午12时00分
aspose-cells版本为24.11
代码如下:
Workbook workbook = new Workbook("date.xlsx");
workbook.getSettings().setRegion(CountryCode.DEFAULT);
workbook.calculateFormula();
for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
Worksheet sheet = workbook.getWorksheets().get(i);
Cells cells = sheet.getCells();
for (int row = 0; row <= cells.getMaxRow(); row++) {
for (int col = 0; col <= cells.getMaxColumn(); col++) {
// 读取单元格内容
System.out.println("row: " + row + ", col: " + col);
Cell cell = cells.get(row, col);
String value = cell.getStringValue();
System.out.println("Value: " + value);
// 获取单元格的显示值
String value_display = cell.getDisplayStringValue();
System.out.println("ValueDisplay: " + value_display);
// 获取单元格的样式
Style style = cell.getStyle();
System.out.println("Style: " + style.getCustom());
}
}
}
对应单元格的输出结果为:
row: 2, col: 0
Value: 上午0时00分
ValueDisplay: 上午0时00分
Style: [DBNum1]上午/下午h"时"mm"分"
可以看到无论是getStringValue还是getDisplayStringValue结果都是错的。
样本:
date.7z (8.3 KB)