mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
🤤release 5.8.33
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.8.33</version>
|
||||
<version>5.8.34-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-poi</artifactId>
|
||||
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.DependencyException;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
@@ -264,7 +265,15 @@ public class ExcelSaxUtil {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
return getNumberValue(Double.parseDouble(value), numFmtString);
|
||||
|
||||
// issue#IB0EJ9 可能精度丢失,对含有小数的value判断并转为BigDecimal
|
||||
final double number = Double.parseDouble(value);
|
||||
if(StrUtil.contains(value, CharUtil.DOT) && !value.equals(Double.toString(number))){
|
||||
// 精度丢失
|
||||
return NumberUtil.toBigDecimal(value);
|
||||
}
|
||||
|
||||
return getNumberValue(number, numFmtString);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -18,9 +18,10 @@ import java.util.List;
|
||||
/**
|
||||
* sheetData标签内容读取处理器
|
||||
*
|
||||
* <pre>
|
||||
* <sheetData></sheetData>
|
||||
* </pre>
|
||||
* <pre>{@code
|
||||
* <sheetData></sheetData>
|
||||
* }</pre>
|
||||
*
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public class SheetDataSaxHandler extends DefaultHandler {
|
||||
@@ -62,7 +63,12 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
// 存储每行的列元素
|
||||
private List<Object> rowCellList = new ArrayList<>();
|
||||
|
||||
public SheetDataSaxHandler(RowHandler rowHandler){
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param rowHandler 行处理器
|
||||
*/
|
||||
public SheetDataSaxHandler(RowHandler rowHandler) {
|
||||
this.rowHandler = rowHandler;
|
||||
}
|
||||
|
||||
@@ -156,7 +162,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
lastFormula.append(ch, start, length);
|
||||
break;
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
// 按理说内容应该为"<v>内容</v>",但是某些特别的XML内容不在v或f标签中,此处做一些兼容
|
||||
// issue#1303@Github
|
||||
lastContent.append(ch, start, length);
|
||||
@@ -292,8 +298,8 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
// 单元格存储格式的索引,对应style.xml中的numFmts元素的子元素索引
|
||||
final int numFmtIndex = xssfCellStyle.getDataFormat();
|
||||
this.numFmtString = ObjectUtil.defaultIfNull(
|
||||
xssfCellStyle.getDataFormatString(),
|
||||
() -> BuiltinFormats.getBuiltinFormat(numFmtIndex));
|
||||
xssfCellStyle.getDataFormatString(),
|
||||
() -> BuiltinFormats.getBuiltinFormat(numFmtIndex));
|
||||
if (CellDataType.NUMBER == this.cellDataType && ExcelSaxUtil.isDateFormat(numFmtIndex, numFmtString)) {
|
||||
cellDataType = CellDataType.DATE;
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ public class IssueIB0EJ9Test {
|
||||
@Test
|
||||
@Disabled
|
||||
void saxReadTest() {
|
||||
ExcelUtil.readBySax(FileUtil.file("d:/test/bbb.xlsx"), "Sheet1",
|
||||
ExcelUtil.readBySax(FileUtil.file("d:/test/数值型测试.xlsx"), "hcm工资表",
|
||||
(sheetIndex, rowIndex, rowlist) -> Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user