Browse Source

修复前面7月20日前提到的bug

bugfix
jipengfei.jpf 6 years ago
parent
commit
40da8d9f09
  1. 2
      pom.xml
  2. 55
      src/main/java/com/alibaba/excel/read/SaxAnalyserV07.java
  3. 5
      src/main/java/com/alibaba/excel/read/v07/RowHandler.java
  4. 2
      src/test/java/read/v07/Read2007Xlsx.java
  5. BIN
      src/test/resources/1.xlsx

2
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>1.0.2</version>
<version>1.0.2-bugfix</version>
<packaging>jar</packaging>
<name>easyexcel</name>
<description>easyexcel is a excel handle tools written in Java</description>

55
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 ("t".equals(qName)) {
lastElementPosition++;
}
}
private boolean hasSkippedEmptySharedString() {
return lastElementPosition > lastHandledElementPosition;
}
//if (hasSkippedEmptySharedString()) {
// sharedStringList.add("");
//}
//if ("t".equals(qName)) {
// lastElementPosition++;
//}
if ("si".equals(qName) || "t".equals(qName)) {
beforeQName = currentQName;
currentQName = qName;
}
}
//@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) {
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++;
}
// lastHandledElementPosition++;
}
});

5
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);
if (idx < sharedStringList.size()) {
currentCellValue = sharedStringList.get(idx);
} else {
currentCellValue = "";
}
currentCellType = FieldType.EMPTY;
break;
//case DATE:

2
src/test/java/read/v07/Read2007Xlsx.java

@ -24,7 +24,7 @@ public class Read2007Xlsx {
//创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List<String>的方式通知监听者
@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<List<String>>() {

BIN
src/test/resources/1.xlsx

Binary file not shown.
Loading…
Cancel
Save