From 4980ee915358f1d010eb76d1604362ea3d0f0f1d Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 2 Sep 2019 09:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8D=A2=E8=A1=8C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=A0=E6=B3=95=E8=AF=BB=E5=8F=96=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v07/SharedStringsTableHandler.java | 24 +++++++---- .../metadata/property/ExcelHeadProperty.java | 4 +- .../easyexcel/test/temp/simple/HgTest.java | 42 +++++++++++++++++++ update.md | 1 + 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java diff --git a/src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java index b4d91777..cca10f65 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/SharedStringsTableHandler.java +++ b/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 (currentElementData != null) { + 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)); } } diff --git a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java b/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java index 2f117e15..a1200d5c 100644 --- a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java +++ b/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); } diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/simple/HgTest.java new file mode 100644 index 00000000..f5c33a2f --- /dev/null +++ b/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 list = + EasyExcel.read(new FileInputStream("D:\\test\\hg2.xlsx")).sheet().headRowNumber(0).doReadSync(); + for (Object data : list) { + LOGGER.info("返回数据:{}", JSON.toJSONString(data)); + } + } + +} diff --git a/update.md b/update.md index c5ee9739..02822274 100644 --- a/update.md +++ b/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 * 优化读写逻辑