fix sax for date bug

This commit is contained in:
Looly 2020-05-31 16:45:37 +08:00
parent 5a99c64226
commit 640312c745
4 changed files with 19 additions and 6 deletions

View File

@ -36,7 +36,8 @@
### Bug修复
* 【core 】 修复SimpleCache死锁问题issue#I1HOKB@Gitee
* 【core 】 修复SemaphoreRunnable释放问题issue#I1HLQQ@Gitee
* 【poi 】 修复Sax方式读取Excel行号错误问题issue#882@Gitee
* 【poi 】 修复Sax方式读取Excel行号错误问题issue#882@Github
* 【poi 】 修复Sax方式读取Excel日期类型数据03和07不一致问题issue#I1HL1C@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -308,7 +308,7 @@ public class Excel03SaxReader extends AbstractExcelSaxReader<Excel03SaxReader> i
value = numrec.getValue();
} else if (formatString.contains(StrUtil.SLASH) || formatString.contains(StrUtil.COLON)) {
//日期
value = formatListener.formatNumberDateCell(numrec);
value = ExcelSaxUtil.getDateValue(numrec.getValue());
} else {
final double doubleValue = numrec.getValue();
final long longPart = (long) doubleValue;

View File

@ -165,6 +165,17 @@ public class ExcelSaxUtil {
}
}
/**
* 获取日期
*
* @param value 单元格值
* @return 日期
* @since 5.3.6
*/
public static DateTime getDateValue(String value) {
return getDateValue(Double.parseDouble(value));
}
/**
* 获取日期
*
@ -172,8 +183,8 @@ public class ExcelSaxUtil {
* @return 日期
* @since 4.1.0
*/
private static DateTime getDateValue(String value) {
return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(Double.parseDouble(value), false));
public static DateTime getDateValue(double value) {
return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value, false));
}
/**

View File

@ -103,8 +103,9 @@ public class ExcelSaxReadTest {
}
@Test
@Ignore
public void dateReadTest(){
ExcelUtil.readBySax("d:/test/sax_test.xls", 0, (RowHandler) (i, i1, list) ->
ExcelUtil.readBySax("d:/test/sax_date_test.xlsx", 0, (i, i1, list) ->
Console.log(StrUtil.join(", ", list)));
};
}
}