Browse Source

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

pull/523/head
Jiaju Zhuang 5 years ago
parent
commit
4980ee9153
  1. 24
      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

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

@ -16,11 +16,11 @@ public class SharedStringsTableHandler extends DefaultHandler {
/** /**
* The final piece of data * The final piece of data
*/ */
private String currentData; private StringBuilder currentData;
/** /**
* Current element data * Current element data
*/ */
private String currentElementData; private StringBuilder currentElementData;
private ReadCache readCache; private ReadCache readCache;
@ -40,20 +40,26 @@ public class SharedStringsTableHandler extends DefaultHandler {
@Override @Override
public void endElement(String uri, String localName, String name) { public void endElement(String uri, String localName, String name) {
if (T_TAG.equals(name)) { if (T_TAG.equals(name)) {
if (currentData == null) { if (currentElementData != null) {
currentData = currentElementData; if (currentData == null) {
} else { currentData = new StringBuilder();
if (currentElementData != null) {
currentData += currentElementData;
} }
currentData.append(currentElementData);
} }
} else if (SI_TAG.equals(name)) { } else if (SI_TAG.equals(name)) {
readCache.put(currentData); if (currentData == null) {
readCache.put(null);
} else {
readCache.put(currentData.toString());
}
} }
} }
@Override @Override
public void characters(char[] ch, int start, int length) { 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; continue;
} }
if (customFiledMap.containsKey(excelProperty.index())) { if (customFiledMap.containsKey(excelProperty.index())) {
throw new ExcelGenerateException("The index of " + customFiledMap.get(excelProperty.index()).getName() throw new ExcelGenerateException("The index of '" + customFiledMap.get(excelProperty.index()).getName()
+ " and " + field.getName() + " must be inconsistent"); + "' and '" + field.getName() + "' must be inconsistent");
} }
customFiledMap.put(excelProperty.index(), field); 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 # 2.0.0-beta2
* 加速gc回收 [Issue #511](https://github.com/alibaba/easyexcel/issues/511) * 加速gc回收 [Issue #511](https://github.com/alibaba/easyexcel/issues/511)
* 修改空字符串读取可能读取上个字段的数据的bug * 修改空字符串读取可能读取上个字段的数据的bug
* 修改换行数据无法读取的bug
# 2.0.0-beta1 # 2.0.0-beta1
* 优化读写逻辑 * 优化读写逻辑

Loading…
Cancel
Save