Browse Source

Merge pull request #2815 from alibaba/bugfix

Bugfix
pull/2818/head
Jiaju Zhuang 2 years ago committed by GitHub
parent
commit
169e4ba0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      README.md
  2. 43
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/sax/SharedStringsTableHandler.java
  3. 24
      easyexcel-core/src/main/java/com/alibaba/excel/constant/ExcelXmlConstants.java
  4. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityTest.java
  5. BIN
      easyexcel-test/src/test/resources/compatibility/t02.xlsx
  6. 2
      pom.xml
  7. 27
      update.md

5
README.md

@ -16,7 +16,8 @@ EasyExcel
[钉钉5群(已满): 32134498](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingb9fa1325d9dccc3ecac589edd02f1650&5233a=71a83&cbdbhh=qwertyuiop)
[钉钉6群(已满): 34707941](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingcf68008a1d443ac012d5427bdb061b7a&6ae36c3d-0c80-4=22398493-6c2a-4&cbdbhh=qwertyuiop)
[钉钉7群(已满): 35235427](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=ding532b9018c06c7fc8660273c4b78e6440&167fb=ed003&cbdbhh=qwertyuiop)
[钉钉8群: 44752220](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingea96808beee421693fd4ba7542d6e5da&0380092a-fa46=a6a40905-7951&cbdbhh=qwertyuiop)
[钉钉8群(已满): 44752220](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingea96808beee421693fd4ba7542d6e5da&0380092a-fa46=a6a40905-7951&cbdbhh=qwertyuiop)
[钉钉9群: 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop)
[官方网站: https://easyexcel.opensource.alibaba.com/](https://easyexcel.opensource.alibaba.com/)
@ -35,7 +36,7 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
</dependency>
```

43
easyexcel-core/src/main/java/com/alibaba/excel/analysis/v07/handlers/sax/SharedStringsTableHandler.java

@ -4,6 +4,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import com.alibaba.excel.cache.ReadCache;
import com.alibaba.excel.constant.ExcelXmlConstants;
/**
* Sax read sharedStringsTable.xml
@ -11,12 +12,6 @@ import com.alibaba.excel.cache.ReadCache;
* @author Jiaju Zhuang
*/
public class SharedStringsTableHandler extends DefaultHandler {
private static final String T_TAG = "t";
private static final String SI_TAG = "si";
/**
* Mac 2016 2017 will have this extra field to ignore
*/
private static final String RPH_TAG = "rPh";
/**
* The final piece of data
@ -43,19 +38,36 @@ public class SharedStringsTableHandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) {
if (T_TAG.equals(name)) {
if (name == null) {
return;
}
switch (name) {
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG:
currentElementData = null;
isTagt = true;
} else if (SI_TAG.equals(name)) {
break;
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG:
currentData = null;
} else if (RPH_TAG.equals(name)) {
break;
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG:
ignoreTagt = true;
break;
default:
// ignore
}
}
@Override
public void endElement(String uri, String localName, String name) {
if (T_TAG.equals(name)) {
if (name == null) {
return;
}
switch (name) {
case ExcelXmlConstants.SHAREDSTRINGS_T_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_T_TAG:
if (currentElementData != null) {
if (currentData == null) {
currentData = new StringBuilder();
@ -63,14 +75,21 @@ public class SharedStringsTableHandler extends DefaultHandler {
currentData.append(currentElementData);
}
isTagt = false;
} else if (SI_TAG.equals(name)) {
break;
case ExcelXmlConstants.SHAREDSTRINGS_SI_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_SI_TAG:
if (currentData == null) {
readCache.put(null);
} else {
readCache.put(currentData.toString());
}
} else if (RPH_TAG.equals(name)) {
break;
case ExcelXmlConstants.SHAREDSTRINGS_RPH_TAG:
case ExcelXmlConstants.SHAREDSTRINGS_X_RPH_TAG:
ignoreTagt = false;
break;
default:
// ignore
}
}

24
easyexcel-core/src/main/java/com/alibaba/excel/constant/ExcelXmlConstants.java

@ -59,4 +59,28 @@ public class ExcelXmlConstants {
*/
public static final String CELL_RANGE_SPLIT = ":";
// The following is a constant read the `SharedStrings.xml`
/**
* text
* https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet
* .text?redirectedfrom=MSDN&view=openxml-2.8.1
*/
public static final String SHAREDSTRINGS_T_TAG = "t";
public static final String SHAREDSTRINGS_X_T_TAG = "x:t";
/**
* SharedStringItem
* https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet
* .sharedstringitem?redirectedfrom=MSDN&view=openxml-2.8.1
*/
public static final String SHAREDSTRINGS_SI_TAG = "si";
public static final String SHAREDSTRINGS_X_SI_TAG = "x:si";
/**
* Mac 2016 2017 will have this extra field to ignore
*/
public static final String SHAREDSTRINGS_RPH_TAG = "rPh";
public static final String SHAREDSTRINGS_X_RPH_TAG = "x:rPh";
}

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/compatibility/CompatibilityTest.java

@ -5,6 +5,7 @@ import java.util.Map;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
@ -30,4 +31,15 @@ public class CompatibilityTest {
Map<Integer, Object> row1 = list.get(1);
Assert.assertEquals("Q235(碳钢)", row1.get(0));
}
@Test
public void t02() {
// Exist in `sharedStrings.xml` `x:t` start tag, need to be compatible
List<Map<Integer, Object>> list = EasyExcel.read(TestFileUtil.getPath() + "compatibility/t02.xlsx").sheet()
.headRowNumber(0).doReadSync();
log.info("data:{}", JSON.toJSONString(list));
Assert.assertEquals(3, list.size());
Map<Integer, Object> row2 = list.get(2);
Assert.assertEquals("1,2-戊二醇", row2.get(2));
}
}

BIN
easyexcel-test/src/test/resources/compatibility/t02.xlsx

Binary file not shown.

2
pom.xml

@ -20,7 +20,7 @@
<properties>
<revision>3.1.2</revision>
<revision>3.1.3</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<gpg.skip>true</gpg.skip>

27
update.md

@ -1,10 +1,17 @@
# 3.1.3
* 提供xlsx兼容性:兼容`sharedStrings.xml` 存储在 `x:t`标签
# 3.1.2
* 修复长时间运行会产生大对象的bug [Issue #2725](https://github.com/alibaba/easyexcel/issues/2725)
# 3.1.1
* 修复部分xlsx无法读取超链接的bug
# 3.1.0
* 支持jdk17,去除cglib&asm依赖,改成重新拷贝一份 [Issue #2240](https://github.com/alibaba/easyexcel/issues/2240)
* 升级ehcache 到 3.9.9 ,为了兼容jdk17
* 在有样式没有数据的情况下也算空行 [Issue #2294](https://github.com/alibaba/easyexcel/issues/2294)
@ -20,24 +27,27 @@
* csv支持设置读写编码 [Issue #2404](https://github.com/alibaba/easyexcel/issues/2404)
* 读写支持`try-with-resources`语法糖
# 3.0.5
* 修复`ReadListener` 转换异常不抛出的问题
# 3.0.4
* 调整读写默认大小,防止大批量写的时候可能会full gc
* `fill`的情况新增 `afterRowDispose`事件
# 3.0.3
* 修复`HeadStyle`无效的bug
# 3.0.2
* 大幅提升读写性能
* 修复列宽注解没用的bug [Issue #2151](https://github.com/alibaba/easyexcel/issues/2151)
* 修复`CellData`接收失败的的bug [Issue #2147](https://github.com/alibaba/easyexcel/issues/2147)
# 3.0.1
* 升级到正式版
* 修复填充样式可能丢失的问题 [Issue #2124](https://github.com/alibaba/easyexcel/issues/2124)
* 修复填充数据为空 可能NPE的bug
@ -45,7 +55,6 @@
* 修复样式可能超过最大限制的bug
* 修复写入过慢的bug
# 3.0.0-beta3
* 修复导出浮点型数据可能精度异常的bug
@ -128,7 +137,8 @@
* 修复xls仅公式行 不读取的bug [Issue #1324](https://github.com/alibaba/easyexcel/issues/1324)
* 修复xls直接读取第2页 `NPE` 的bug [Issue #1280](https://github.com/alibaba/easyexcel/issues/1280)
* 修复填充的时候,最后一行中间有空行会创建失败的bug
* 修复`includeColumnIndexes`不包含第列 会无法导出数据的bug [Issue #1346](https://github.com/alibaba/easyexcel/issues/1346)
* 修复`includeColumnIndexes`不包含第列
会无法导出数据的bug [Issue #1346](https://github.com/alibaba/easyexcel/issues/1346)
* 修复`@NumberFormat`注解转换double时可能会丢失精度 [Issue #1306](https://github.com/alibaba/easyexcel/issues/1306)
# 2.2.3
@ -145,11 +155,14 @@
* 发布正式版
* 修复第一行为空不会调用`invokeHeadMap`的bug [Issue #993](https://github.com/alibaba/easyexcel/issues/993)
* 当类的属性没有按照ExcelProperty的属性index顺序排序的时候,写数据出现错乱 [Issue #1046](https://github.com/alibaba/easyexcel/issues/1046)
* 新增支持自定义转换器 入参可以为空 实现`NullableObjectConverter` 即可 [Issue #1084](https://github.com/alibaba/easyexcel/issues/1084)
*
当类的属性没有按照ExcelProperty的属性index顺序排序的时候,写数据出现错乱 [Issue #1046](https://github.com/alibaba/easyexcel/issues/1046)
* 新增支持自定义转换器 入参可以为空 实现`NullableObjectConverter`
即可 [Issue #1084](https://github.com/alibaba/easyexcel/issues/1084)
* 修复xls丢失结束标记的情况下 会漏读最后一行
* 修复填充的时候 多次`forceNewRow` 空指针的bug [Issue #1201](https://github.com/alibaba/easyexcel/issues/1201)
* 修复`table`、`sheet`中创建的拦截器不执行`workbook`事件的bug [Issue #1202](https://github.com/alibaba/easyexcel/issues/1202)
* 修复`table`、`sheet`中创建的拦截器不执行`workbook`
事件的bug [Issue #1202](https://github.com/alibaba/easyexcel/issues/1202)
# 2.2.0-beta2

Loading…
Cancel
Save