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修复 ### Bug修复
* 【core 】 修复SimpleCache死锁问题issue#I1HOKB@Gitee * 【core 】 修复SimpleCache死锁问题issue#I1HOKB@Gitee
* 【core 】 修复SemaphoreRunnable释放问题issue#I1HLQQ@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(); value = numrec.getValue();
} else if (formatString.contains(StrUtil.SLASH) || formatString.contains(StrUtil.COLON)) { } else if (formatString.contains(StrUtil.SLASH) || formatString.contains(StrUtil.COLON)) {
//日期 //日期
value = formatListener.formatNumberDateCell(numrec); value = ExcelSaxUtil.getDateValue(numrec.getValue());
} else { } else {
final double doubleValue = numrec.getValue(); final double doubleValue = numrec.getValue();
final long longPart = (long) doubleValue; 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 日期 * @return 日期
* @since 4.1.0 * @since 4.1.0
*/ */
private static DateTime getDateValue(String value) { public static DateTime getDateValue(double value) {
return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(Double.parseDouble(value), false)); return DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value, false));
} }
/** /**

View File

@ -103,8 +103,9 @@ public class ExcelSaxReadTest {
} }
@Test @Test
@Ignore
public void dateReadTest(){ 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))); Console.log(StrUtil.join(", ", list)));
}; }
} }