Browse Source

Merge branch 'master' into 2.1.0-beta1

# Conflicts:
#	pom.xml
#	src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
#	update.md
pull/635/head
Jiaju Zhuang 5 years ago
parent
commit
3f829efadc
  1. 2
      quickstart.md
  2. 17
      src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
  3. 3
      src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
  4. 6
      src/main/java/com/alibaba/excel/util/NumberUtils.java
  5. 4
      update.md

2
quickstart.md

@ -7,9 +7,11 @@
* 单个文件的并发写入、读取
* 读取图片
* 宏
ClassNotFoundException与java.lang.NoClassDefFoundError的区别
* csv读取(这个后续可能会考虑)
#### 常见问题
* 关于@Data,读写的对象都用到了[Lombok](https://www.projectlombok.org/),他会自动生成`get`,`set` ,如果不需要的话,自己创建对象并生成`get`,`set` 。
* 出现`NoSuchMethodException`,`ClassNotFoundException`,`NoClassDefFoundError`极大概率是jar冲突,建议`clean`项目,或者统一`poi` 的版本,理论上来说`easyexcel`兼容poi的`3.17`,`4.0.1`,`4.1.0`所有较新版本
* 如果在读的时候`Listener`里面需要使用spring的`@Autowired`,给`Listener`创建成员变量,然后在构造方法里面传进去。而别必须不让spring管理`Listener`,每次读取都要`new`一个。
* 如果用`String`去接收数字,出现小数点等情况,这个是BUG,但是很难修复,后续版本会修复这个问题。目前请使用`@NumberFormat`直接,里面的参数就是调用了java自带的`NumberFormat.format`方法,不知道怎么入参的可以自己网上查询。
#### 详细参数介绍

17
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

@ -33,6 +33,7 @@ import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.excel.util.FileUtils;
/**
@ -60,14 +61,18 @@ public class XlsxSaxAnalyser implements ExcelExecutor {
OPCPackage pkg = readOpcPackage(readWorkbookHolder, decryptedStream);
readWorkbookHolder.setOpcPackage(pkg);
PackagePart sharedStringsTablePackagePart =
pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()).get(0);
// Specify default cache
defaultReadCache(readWorkbookHolder, sharedStringsTablePackagePart);
ArrayList<PackagePart> packageParts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
// Analysis sharedStringsTable.xml
analysisSharedStringsTable(sharedStringsTablePackagePart.getInputStream(), readWorkbookHolder);
if (!CollectionUtils.isEmpty(packageParts)) {
PackagePart sharedStringsTablePackagePart = packageParts.get(0);
// Specify default cache
defaultReadCache(readWorkbookHolder, sharedStringsTablePackagePart);
// Analysis sharedStringsTable.xml
analysisSharedStringsTable(sharedStringsTablePackagePart.getInputStream(), readWorkbookHolder);
}
XSSFReader xssfReader = new XSSFReader(pkg);
analysisUse1904WindowDate(xssfReader, readWorkbookHolder);

3
src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java

@ -27,7 +27,6 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.util.StringUtils;
/**
* Cell Handler
@ -106,6 +105,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
@Override
public void endHandle(String name) {
currentTagDeque.pop();
// cell is formula
if (CELL_FORMULA_TAG.equals(name)) {
currentCellData.setFormulaValue(formulaStringBuilder.toString());
@ -158,7 +158,6 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
currentCellData.checkEmpty();
curRowContent.put(curCol, currentCellData);
}
currentTagDeque.pop();
}
@Override

6
src/main/java/com/alibaba/excel/util/NumberUtils.java

@ -26,7 +26,11 @@ public class NumberUtils {
public static String format(Number num, ExcelContentProperty contentProperty) {
if (contentProperty == null || contentProperty.getNumberFormatProperty() == null
|| StringUtils.isEmpty(contentProperty.getNumberFormatProperty().getFormat())) {
return num.toString();
if (num instanceof BigDecimal) {
return ((BigDecimal)num).toPlainString();
} else {
return num.toString();
}
}
String format = contentProperty.getNumberFormatProperty().getFormat();
RoundingMode roundingMode = contentProperty.getNumberFormatProperty().getRoundingMode();

4
update.md

@ -4,6 +4,10 @@
* 新增支持读取单元格类型、写入指定单元格类型
* 支持通过模板填充数据
# 2.0.4
* 修复07版整个excel仅存在数字时会出现的NPE
* 修复03版 用String接收电话会出现科学计数法的问题
# 2.0.3
* 修复重大bug 在07版读取文件的时候 小概率导致数字部分丢失

Loading…
Cancel
Save