mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix sax 03 bug
This commit is contained in:
parent
bee588de3c
commit
7bfb8e82cf
@ -16,6 +16,7 @@
|
||||
* 【core 】 修复FileUtil中,copyFile方法断言判断参数传递错误(issue#I1Z2NY@Gitee)
|
||||
* 【core 】 修复BeanDesc读取父类属性覆盖子类属性导致的问题(pr#1175@Github)
|
||||
* 【aop 】 修复SimpleAspect一个重载导致的问题,去掉重载的after方法(issue#I1YUG9@Gitee)
|
||||
* 【poi 】 修复03 sax读取日期问题(issue#I1Z83N@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.poi.excel.sax;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -14,7 +15,19 @@ import org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener;
|
||||
import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
|
||||
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
|
||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||
import org.apache.poi.hssf.record.*;
|
||||
import org.apache.poi.hssf.record.BOFRecord;
|
||||
import org.apache.poi.hssf.record.BlankRecord;
|
||||
import org.apache.poi.hssf.record.BoolErrRecord;
|
||||
import org.apache.poi.hssf.record.BoundSheetRecord;
|
||||
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
||||
import org.apache.poi.hssf.record.EOFRecord;
|
||||
import org.apache.poi.hssf.record.FormulaRecord;
|
||||
import org.apache.poi.hssf.record.LabelRecord;
|
||||
import org.apache.poi.hssf.record.LabelSSTRecord;
|
||||
import org.apache.poi.hssf.record.NumberRecord;
|
||||
import org.apache.poi.hssf.record.Record;
|
||||
import org.apache.poi.hssf.record.SSTRecord;
|
||||
import org.apache.poi.hssf.record.StringRecord;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
||||
@ -294,12 +307,10 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader<Excel03Sax
|
||||
case NumberRecord.sid: // 数字类型
|
||||
final NumberRecord numrec = (NumberRecord) record;
|
||||
final String formatString = formatListener.getFormatString(numrec);
|
||||
if (StrUtil.contains(formatString, StrUtil.DOT)) {
|
||||
//浮点数
|
||||
value = numrec.getValue();
|
||||
} else if (StrUtil.containsAny(formatString, StrUtil.SLASH, StrUtil.COLON, "年", "月", "日", "时", "分", "秒")) {
|
||||
//日期
|
||||
value = ExcelSaxUtil.getDateValue(numrec.getValue());
|
||||
if(false == StrUtil.contains(formatString, '%') &&
|
||||
false == "General".equalsIgnoreCase(formatString)){
|
||||
// 可能为日期格式
|
||||
value = DateUtil.date(org.apache.poi.ss.usermodel.DateUtil.getJavaDate(numrec.getValue()));
|
||||
} else {
|
||||
final double doubleValue = numrec.getValue();
|
||||
final long longPart = (long) doubleValue;
|
||||
|
@ -114,5 +114,5 @@ public interface ExcelSaxReader<T> {
|
||||
*/
|
||||
default T read(InputStream in, int rid) throws POIException{
|
||||
return read(in, String.valueOf(rid));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class ExcelSaxReadTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void dateReadTest() {
|
||||
ExcelUtil.readBySax("d:/test/sax_date_test.xlsx", 0, (i, i1, list) ->
|
||||
ExcelUtil.readBySax("d:/test/date_test.xls", 0, (i, i1, list) ->
|
||||
Console.log(StrUtil.join(", ", list)));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user