mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复ExcelReader读取时间变成12小时形式问题
This commit is contained in:
parent
f51df24970
commit
9dfac34f69
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.8.8.M1 (2022-09-23)
|
||||
# 5.8.8.M1 (2022-09-24)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 StreamUtil.of方法新增对 Iterator 支持;StreamUtil.of(Iterable) 方法优化(pr#807@Gitee)
|
||||
@ -19,6 +19,7 @@
|
||||
* 【core 】 修复ObjectUtil.defaultIfNull去掉误加的deprecated(issue#I5SIZT@Gitee)
|
||||
* 【core 】 修复ReflectUtil 反射方法中桥接判断问题(issue#2625@Github)
|
||||
* 【poi 】 修复ExcelWriter导出List<Map>引起的个数混乱问题(issue#2627@Github)
|
||||
* 【poi 】 修复ExcelReader读取时间变成12小时形式问题(issue#I5Q1TW@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -4,11 +4,12 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.cell.CellValue;
|
||||
import java.util.Date;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.util.NumberToTextConverter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 数字类型单元格值<br>
|
||||
* 单元格值可能为Long、Double、Date
|
||||
@ -37,10 +38,10 @@ public class NumericCellValue implements CellValue<Object> {
|
||||
if (null != style) {
|
||||
// 判断是否为日期
|
||||
if (ExcelDateUtil.isDateFormat(cell)) {
|
||||
// 1899年写入会导致数据错乱,读取到1899年证明这个单元格的信息不关注年月日
|
||||
Date dateCellValue = cell.getDateCellValue();
|
||||
if ("1899".equals(DateUtil.format(dateCellValue, "yyyy"))) {
|
||||
return DateUtil.format(dateCellValue, style.getDataFormatString());
|
||||
final LocalDateTime dateCellValue = cell.getLocalDateTimeCellValue();
|
||||
if(1899 == dateCellValue.getYear()){
|
||||
// 1899年写入会导致数据错乱,读取到1899年证明这个单元格的信息不关注年月日
|
||||
return dateCellValue.toLocalTime();
|
||||
}
|
||||
// 使用Hutool的DateTime包装
|
||||
return DateUtil.date(dateCellValue);
|
||||
|
20
hutool-poi/src/test/java/cn/hutool/poi/IssueI5Q1TWTest.java
Normal file
20
hutool-poi/src/test/java/cn/hutool/poi/IssueI5Q1TWTest.java
Normal file
@ -0,0 +1,20 @@
|
||||
package cn.hutool.poi;
|
||||
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IssueI5Q1TWTest {
|
||||
|
||||
@Test
|
||||
public void readTest() {
|
||||
final ExcelReader reader = ExcelUtil.getReader("I5Q1TW.xlsx");
|
||||
|
||||
// 自定义时间格式1
|
||||
Assert.assertEquals("18:56", reader.readCellValue(0, 0).toString());
|
||||
|
||||
// 自定义时间格式2
|
||||
Assert.assertEquals("18:56", reader.readCellValue(1, 0).toString());
|
||||
}
|
||||
}
|
BIN
hutool-poi/src/test/resources/I5Q1TW.xlsx
Normal file
BIN
hutool-poi/src/test/resources/I5Q1TW.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user