Looly 5 years ago
parent
commit
30e1eb929c

+ 2 - 0
CHANGELOG.md

@@ -23,6 +23,8 @@
 * 【core   】     修复TemporalAccessorUtil无法格式化LocalDate带时间问题(issue#1289@Github)
 * 【json   】     修复自定义日期格式的LocalDateTime没有包装引号问题(issue#1289@Github)
 * 【cache  】     get中unlock改为unlockRead(issue#1294@Github)
+* 【db     】     修复表名包含点导致的问题(issue#1300@Github)
+* 【poi    】     修复xdr:row标签导致的问题(issue#1297@Github)
 
 -------------------------------------------------------------------------------------------------------------
 

+ 2 - 1
hutool-db/src/main/java/cn/hutool/db/sql/Wrapper.java

@@ -1,5 +1,6 @@
 package cn.hutool.db.sql;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.Editor;
 import cn.hutool.core.util.ArrayUtil;
@@ -98,7 +99,7 @@ public class Wrapper {
 		
 		//对于Oracle这类数据库,表名中包含用户名需要单独拆分包装
 		if(field.contains(StrUtil.DOT)){
-			final Collection<String> target = CollectionUtil.filter(StrUtil.split(field, StrUtil.C_DOT), (Editor<String>) t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
+			final Collection<String> target = CollUtil.filter(StrUtil.split(field, StrUtil.C_DOT, 2), (Editor<String>) t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
 			return CollectionUtil.join(target, StrUtil.DOT);
 		}
 		

+ 37 - 5
hutool-poi/src/main/java/cn/hutool/poi/excel/sax/Excel07SaxReader.java

@@ -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);
 			}
 		}
 	}

+ 8 - 0
hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelSaxReadTest.java

@@ -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);
+		});
+	}
 }