mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bugs
This commit is contained in:
@@ -66,6 +66,8 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
private XSSFCellStyle xssfCellStyle;
|
||||
// 单元格存储的格式化字符串,nmtFmt的formatCode属性的值
|
||||
private String numFmtString;
|
||||
// 是否处于sheetData标签内,sax只解析此标签内的内容,其它标签忽略
|
||||
private boolean isInSheetData;
|
||||
|
||||
// 上一次的内容
|
||||
private final StrBuilder lastContent = StrUtil.strBuilder();
|
||||
@@ -195,7 +197,17 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
*/
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
final ElementName name = ElementName.of(localName);
|
||||
if("sheetData".equals(qName)){
|
||||
this.isInSheetData = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(false == this.isInSheetData){
|
||||
// 非sheetData标签,忽略解析
|
||||
return;
|
||||
}
|
||||
|
||||
final ElementName name = ElementName.of(qName);
|
||||
this.curElementName = name;
|
||||
|
||||
if(null != name){
|
||||
@@ -217,12 +229,24 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
*/
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if("sheetData".equals(qName)){
|
||||
// sheetData结束,不再解析别的标签
|
||||
this.isInSheetData = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(false == this.isInSheetData){
|
||||
// 非sheetData标签,忽略解析
|
||||
return;
|
||||
}
|
||||
|
||||
this.curElementName = null;
|
||||
if (ElementName.c.match(localName)) { // 单元格结束
|
||||
if (ElementName.c.match(qName)) { // 单元格结束
|
||||
endCell();
|
||||
} else if (ElementName.row.match(localName)) {// 行结束
|
||||
} else if (ElementName.row.match(qName)) {// 行结束
|
||||
endRow();
|
||||
}
|
||||
// 其它标签忽略
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,6 +254,11 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
*/
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if(false == this.isInSheetData){
|
||||
// 非sheetData标签,忽略解析
|
||||
return;
|
||||
}
|
||||
|
||||
final ElementName elementName = this.curElementName;
|
||||
if(null != elementName){
|
||||
switch (elementName){
|
||||
@@ -303,7 +332,10 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
* @param attributes 属性列表
|
||||
*/
|
||||
private void startRow(Attributes attributes) {
|
||||
this.rowNumber = Long.parseLong(AttributeName.r.getValue(attributes)) - 1;
|
||||
final String rValue = AttributeName.r.getValue(attributes);
|
||||
if(null != rValue){
|
||||
this.rowNumber = Long.parseLong(rValue) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +431,7 @@ public class Excel07SaxReader extends DefaultHandler implements ExcelSaxReader<E
|
||||
len++;
|
||||
}
|
||||
while (len-- > 0) {
|
||||
addCellValue(curCell++, "");
|
||||
addCellValue(curCell++, StrUtil.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -175,4 +175,12 @@ public class ExcelSaxReadTest {
|
||||
|
||||
ExcelUtil.getReader(file).read().forEach(Console::log);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void readXlsmTest(){
|
||||
ExcelUtil.readBySax("d:/test/WhiteListTemplate.xlsm", -1, (sheetIndex, rowIndex, rowlist) -> {
|
||||
Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user