Browse Source

修改换行数据无法读取的bug

developing
Jiaju Zhuang 5 years ago
parent
commit
4980ee9153
  1. 22
      src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java
  2. 4
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  3. 42
      src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java
  4. 1
      update.md

22
src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java

@ -16,11 +16,11 @@ public class SharedStringsTableHandler extends DefaultHandler {
/**
* The final piece of data
*/
private String currentData;
private StringBuilder currentData;
/**
* Current element data
*/
private String currentElementData;
private StringBuilder currentElementData;
private ReadCache readCache;
@ -40,20 +40,26 @@ public class SharedStringsTableHandler extends DefaultHandler {
@Override
public void endElement(String uri, String localName, String name) {
if (T_TAG.equals(name)) {
if (currentData == null) {
currentData = currentElementData;
} else {
if (currentElementData != null) {
currentData += currentElementData;
if (currentData == null) {
currentData = new StringBuilder();
}
currentData.append(currentElementData);
}
} else if (SI_TAG.equals(name)) {
readCache.put(currentData);
if (currentData == null) {
readCache.put(null);
} else {
readCache.put(currentData.toString());
}
}
}
@Override
public void characters(char[] ch, int start, int length) {
currentElementData = new String(ch, start, length);
if (currentElementData == null) {
currentElementData = new StringBuilder();
}
currentElementData.append(new String(ch, start, length));
}
}

4
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -137,8 +137,8 @@ public class ExcelHeadProperty {
continue;
}
if (customFiledMap.containsKey(excelProperty.index())) {
throw new ExcelGenerateException("The index of " + customFiledMap.get(excelProperty.index()).getName()
+ " and " + field.getName() + " must be inconsistent");
throw new ExcelGenerateException("The index of '" + customFiledMap.get(excelProperty.index()).getName()
+ "' and '" + field.getName() + "' must be inconsistent");
}
customFiledMap.put(excelProperty.index(), field);
}

42
src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java

@ -0,0 +1,42 @@
package com.alibaba.easyexcel.test.temp.simple;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.temp.poi.PoiTest;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
/**
* 测试poi
*
* @author Jiaju Zhuang
**/
@Ignore
public class HgTest {
private static final Logger LOGGER = LoggerFactory.getLogger(HgTest.class);
@Test
public void hh() throws IOException {
List<Object> list =
EasyExcel.read(new FileInputStream("D:\\test\\hg2.xlsx")).sheet().headRowNumber(0).doReadSync();
for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data));
}
}
}

1
update.md

@ -1,6 +1,7 @@
# 2.0.0-beta2
* 加速gc回收 [Issue #511](https://github.com/alibaba/easyexcel/issues/511)
* 修改空字符串读取可能读取上个字段的数据的bug
* 修改换行数据无法读取的bug
# 2.0.0-beta1
* 优化读写逻辑

Loading…
Cancel
Save