diff --git a/pom.xml b/pom.xml
index fcfcc3f..ec91e9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.alibaba
easyexcel
- 1.0.2
+ 1.0.2-bugfix
jar
easyexcel
easyexcel is a excel handle tools written in Java
diff --git a/src/main/java/com/alibaba/excel/read/SaxAnalyserV07.java b/src/main/java/com/alibaba/excel/read/SaxAnalyserV07.java
index a60771e..8b6c8b7 100644
--- a/src/main/java/com/alibaba/excel/read/SaxAnalyserV07.java
+++ b/src/main/java/com/alibaba/excel/read/SaxAnalyserV07.java
@@ -177,6 +177,7 @@ public class SaxAnalyserV07 extends BaseSaxAnalyser {
XmlParserFactory.parse(workbookXml, new DefaultHandler() {
private int id = 0;
+
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.toLowerCase(Locale.US).equals("sheet")) {
@@ -223,28 +224,54 @@ public class SaxAnalyserV07 extends BaseSaxAnalyser {
//this.sharedStringsTable.readFrom(inputStream);
XmlParserFactory.parse(inputStream, new DefaultHandler() {
- int lastElementPosition = -1;
+ //int lastElementPosition = -1;
+ //
+ //int lastHandledElementPosition = -1;
+
+ String beforeQName = "";
- int lastHandledElementPosition = -1;
+ String currentQName = "";
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
- if (hasSkippedEmptySharedString()) {
- sharedStringList.add("");
+ //if (hasSkippedEmptySharedString()) {
+ // sharedStringList.add("");
+ //}
+ //if ("t".equals(qName)) {
+ // lastElementPosition++;
+ //}
+ if ("si".equals(qName) || "t".equals(qName)) {
+ beforeQName = currentQName;
+ currentQName = qName;
}
- if ("t".equals(qName)) {
- lastElementPosition++;
- }
- }
-
- private boolean hasSkippedEmptySharedString() {
- return lastElementPosition > lastHandledElementPosition;
}
+ //@Override
+ //public void endElement (String uri, String localName, String qName)
+ // throws SAXException
+ //{
+ // if ("si".equals(qName) || "t".equals(qName)) {
+ // beforeQName = qName;
+ // currentQName = "";
+ // }
+ //}
+
+ //private boolean hasSkippedEmptySharedString() {
+ // return lastElementPosition > lastHandledElementPosition;
+ //}
@Override
public void characters(char[] ch, int start, int length) {
- sharedStringList.add(new String(ch, start, length));
- lastHandledElementPosition++;
+ if ("t".equals(currentQName) && ("t".equals(beforeQName))) {
+ String pre = sharedStringList.get(sharedStringList.size() - 1);
+ String str = pre + new String(ch, start, length);
+ sharedStringList.remove(sharedStringList.size() - 1);
+ sharedStringList.add(str);
+ }else if ("t".equals(currentQName) && ("si".equals(beforeQName))){
+ sharedStringList.add(new String(ch, start, length));
+ }
+ // lastHandledElementPosition++;
+
+
}
});
diff --git a/src/main/java/com/alibaba/excel/read/v07/RowHandler.java b/src/main/java/com/alibaba/excel/read/v07/RowHandler.java
index d068df2..7aaf6c9 100644
--- a/src/main/java/com/alibaba/excel/read/v07/RowHandler.java
+++ b/src/main/java/com/alibaba/excel/read/v07/RowHandler.java
@@ -23,7 +23,6 @@ import static com.alibaba.excel.util.ExcelXmlConstants.ROW_TAG;
/**
* @author jipengfei
- *
*/
public class RowHandler extends DefaultHandler {
@@ -108,7 +107,11 @@ public class RowHandler extends DefaultHandler {
switch (currentCellType) {
case STRING:
int idx = Integer.parseInt(currentCellValue);
- currentCellValue = sharedStringList.get(idx);
+ if (idx < sharedStringList.size()) {
+ currentCellValue = sharedStringList.get(idx);
+ } else {
+ currentCellValue = "";
+ }
currentCellType = FieldType.EMPTY;
break;
//case DATE:
diff --git a/src/test/java/read/v07/Read2007Xlsx.java b/src/test/java/read/v07/Read2007Xlsx.java
index b9cb256..fa1958e 100644
--- a/src/test/java/read/v07/Read2007Xlsx.java
+++ b/src/test/java/read/v07/Read2007Xlsx.java
@@ -24,7 +24,7 @@ public class Read2007Xlsx {
//创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List的方式通知监听者
@Test
public void noModel() {
- InputStream inputStream = getInputStream("2007NoModelBigFile.xlsx");
+ InputStream inputStream = getInputStream("1.xlsx");
try {
ExcelReader reader = new ExcelReader(inputStream, ExcelTypeEnum.XLSX, null,
new AnalysisEventListener>() {
diff --git a/src/test/resources/1.xlsx b/src/test/resources/1.xlsx
new file mode 100644
index 0000000..609646c
Binary files /dev/null and b/src/test/resources/1.xlsx differ