Commit 334261a74e9dd2573fd1ed7258dd717ed7fcd5ed
1 parent
bdc29d2c
Exists in
master
fix a bug about read hidden line
Showing
5 changed files
with
24 additions
and
12 deletions
Show diff stats
build.gradle
@@ -54,7 +54,7 @@ uploadArchives { | @@ -54,7 +54,7 @@ uploadArchives { | ||
54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
55 | } | 55 | } |
56 | pom.project { | 56 | pom.project { |
57 | - version '2.2.18' | 57 | + version '2.2.20' |
58 | artifactId ARTIFACT_Id | 58 | artifactId ARTIFACT_Id |
59 | groupId GROUP_ID | 59 | groupId GROUP_ID |
60 | packaging TYPE | 60 | packaging TYPE |
src/main/java/com/taover/easyexcel/analysis/v07/XlsxSaxAnalyser.java
1 | package com.taover.easyexcel.analysis.v07; | 1 | package com.taover.easyexcel.analysis.v07; |
2 | 2 | ||
3 | import java.io.BufferedInputStream; | 3 | import java.io.BufferedInputStream; |
4 | +import java.io.ByteArrayInputStream; | ||
5 | +import java.io.ByteArrayOutputStream; | ||
4 | import java.io.File; | 6 | import java.io.File; |
5 | import java.io.IOException; | 7 | import java.io.IOException; |
6 | import java.io.InputStream; | 8 | import java.io.InputStream; |
@@ -172,8 +174,8 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | @@ -172,8 +174,8 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | ||
172 | } | 174 | } |
173 | 175 | ||
174 | private void parseXmlSource(InputStream inputStream, ContentHandler handler) { | 176 | private void parseXmlSource(InputStream inputStream, ContentHandler handler) { |
175 | - InputSource inputSource = new InputSource(inputStream); | ||
176 | - //this.printInputSource(inputSource); | 177 | + //InputSource inputSource = new InputSource(this.printInputSource(inputStream)); |
178 | + InputSource inputSource = new InputSource(inputStream); | ||
177 | try { | 179 | try { |
178 | SAXParserFactory saxFactory; | 180 | SAXParserFactory saxFactory; |
179 | String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName(); | 181 | String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName(); |
@@ -209,22 +211,29 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | @@ -209,22 +211,29 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | ||
209 | } | 211 | } |
210 | } | 212 | } |
211 | 213 | ||
212 | - private void printInputSource(InputSource inputSource) { | ||
213 | - BufferedInputStream bis = new BufferedInputStream(inputSource.getByteStream()); | ||
214 | - byte[] buffer = new byte[1000*1024]; | 214 | + private InputStream printInputSource(InputStream inputStream) { |
215 | + ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
216 | + byte[] buffer = new byte[1000*1024]; | ||
217 | + BufferedInputStream bis = new BufferedInputStream(inputStream); | ||
215 | try { | 218 | try { |
216 | - int len = bis.read(buffer); | ||
217 | - String data = new String(buffer, 0, len); | ||
218 | - System.out.println(data); | 219 | + int len = -1; |
220 | + while( (len = bis.read(buffer)) != -1) { | ||
221 | + bos.write(buffer, 0, len); | ||
222 | + } | ||
219 | bis.close(); | 223 | bis.close(); |
224 | + bos.close(); | ||
225 | + System.out.println(">>>parseXmlSource(inputStream)"); | ||
226 | + System.out.println(new String(bos.toByteArray())); | ||
220 | } catch (IOException e1) { | 227 | } catch (IOException e1) { |
221 | try { | 228 | try { |
222 | bis.close(); | 229 | bis.close(); |
230 | + bos.close(); | ||
223 | } catch (IOException e) { | 231 | } catch (IOException e) { |
224 | e.printStackTrace(); | 232 | e.printStackTrace(); |
225 | } | 233 | } |
226 | e1.printStackTrace(); | 234 | e1.printStackTrace(); |
227 | } | 235 | } |
236 | + return new ByteArrayInputStream(bos.toByteArray()); | ||
228 | } | 237 | } |
229 | 238 | ||
230 | @Override | 239 | @Override |
src/main/java/com/taover/easyexcel/analysis/v07/handlers/RowTagHandler.java
@@ -35,8 +35,9 @@ public class RowTagHandler extends AbstractXlsxTagHandler { | @@ -35,8 +35,9 @@ public class RowTagHandler extends AbstractXlsxTagHandler { | ||
35 | public boolean isHiddenRow(Attributes attributes) { | 35 | public boolean isHiddenRow(Attributes attributes) { |
36 | int attLen = attributes.getLength(); | 36 | int attLen = attributes.getLength(); |
37 | for(int i=0; i<attLen; ++i) { | 37 | for(int i=0; i<attLen; ++i) { |
38 | - if(ExcelXmlConstants.ATTRIBUTE_HIDDEN.equals(attributes.getLocalName(i)) | ||
39 | - || ExcelXmlConstants.ATTRIBUTE_HIDDEN.equals(attributes.getQName(i))) { | 38 | + if((ExcelXmlConstants.ATTRIBUTE_HIDDEN.equals(attributes.getLocalName(i)) |
39 | + || ExcelXmlConstants.ATTRIBUTE_HIDDEN.equals(attributes.getQName(i))) | ||
40 | + && !"false".equals(attributes.getValue(i))) { | ||
40 | return true; | 41 | return true; |
41 | } | 42 | } |
42 | } | 43 | } |
src/main/java/com/taover/easyexcel/context/AnalysisContextImpl.java
@@ -88,7 +88,7 @@ public class AnalysisContextImpl implements AnalysisContext { | @@ -88,7 +88,7 @@ public class AnalysisContextImpl implements AnalysisContext { | ||
88 | } | 88 | } |
89 | readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo()); | 89 | readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo()); |
90 | if (LOGGER.isDebugEnabled()) { | 90 | if (LOGGER.isDebugEnabled()) { |
91 | - LOGGER.debug("Began to read:{}", readSheetHolder); | 91 | + LOGGER.debug("======Began to read:{}======", readSheetHolder); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 |
src/test/java/com/taover/easyexcel/test/WbTest.java
@@ -10,7 +10,9 @@ import com.taover.easyexcel.EasyExcel; | @@ -10,7 +10,9 @@ import com.taover.easyexcel.EasyExcel; | ||
10 | 10 | ||
11 | public class WbTest { | 11 | public class WbTest { |
12 | public static void main(String[] args) { | 12 | public static void main(String[] args) { |
13 | + //File dataFile = new File("C:\\Users\\Administrator\\Desktop\\数据为空\\好合意商城_20210127_16_47(1).xlsx"); | ||
13 | File dataFile = new File("C:\\Users\\Administrator\\Desktop\\Excel隐藏行\\配送确认1.16(1).xlsx"); | 14 | File dataFile = new File("C:\\Users\\Administrator\\Desktop\\Excel隐藏行\\配送确认1.16(1).xlsx"); |
15 | + //File dataFile = new File("C:\\Users\\Administrator\\Desktop\\表头匹配-测试文件\\多sheet-多个可用-数据有无.xlsx"); | ||
14 | // List<List<Object>> data = transListMapTo2List(EasyExcel.read(dataFile).readHiddenRow(false).headRowNumber(0).doReadSelectedSync()); | 16 | // List<List<Object>> data = transListMapTo2List(EasyExcel.read(dataFile).readHiddenRow(false).headRowNumber(0).doReadSelectedSync()); |
15 | // for(List<Object> row: data) { | 17 | // for(List<Object> row: data) { |
16 | // for(Object item: row) { | 18 | // for(Object item: row) { |