Commit 334261a74e9dd2573fd1ed7258dd717ed7fcd5ed

Authored by 王彬
1 parent bdc29d2c
Exists in master

fix a bug about read hidden line

build.gradle
... ... @@ -54,7 +54,7 @@ uploadArchives {
54 54 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
55 55 }
56 56 pom.project {
57   - version '2.2.18'
  57 + version '2.2.20'
58 58 artifactId ARTIFACT_Id
59 59 groupId GROUP_ID
60 60 packaging TYPE
... ...
src/main/java/com/taover/easyexcel/analysis/v07/XlsxSaxAnalyser.java
1 1 package com.taover.easyexcel.analysis.v07;
2 2  
3 3 import java.io.BufferedInputStream;
  4 +import java.io.ByteArrayInputStream;
  5 +import java.io.ByteArrayOutputStream;
4 6 import java.io.File;
5 7 import java.io.IOException;
6 8 import java.io.InputStream;
... ... @@ -172,8 +174,8 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
172 174 }
173 175  
174 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 179 try {
178 180 SAXParserFactory saxFactory;
179 181 String xlsxSAXParserFactoryName = xlsxReadContext.xlsxReadWorkbookHolder().getSaxParserFactoryName();
... ... @@ -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 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 223 bis.close();
  224 + bos.close();
  225 + System.out.println(">>>parseXmlSource(inputStream)");
  226 + System.out.println(new String(bos.toByteArray()));
220 227 } catch (IOException e1) {
221 228 try {
222 229 bis.close();
  230 + bos.close();
223 231 } catch (IOException e) {
224 232 e.printStackTrace();
225 233 }
226 234 e1.printStackTrace();
227 235 }
  236 + return new ByteArrayInputStream(bos.toByteArray());
228 237 }
229 238  
230 239 @Override
... ...
src/main/java/com/taover/easyexcel/analysis/v07/handlers/RowTagHandler.java
... ... @@ -35,8 +35,9 @@ public class RowTagHandler extends AbstractXlsxTagHandler {
35 35 public boolean isHiddenRow(Attributes attributes) {
36 36 int attLen = attributes.getLength();
37 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 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 88 }
89 89 readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo());
90 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 10  
11 11 public class WbTest {
12 12 public static void main(String[] args) {
  13 + //File dataFile = new File("C:\\Users\\Administrator\\Desktop\\数据为空\\好合意商城_20210127_16_47(1).xlsx");
13 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 16 // List<List<Object>> data = transListMapTo2List(EasyExcel.read(dataFile).readHiddenRow(false).headRowNumber(0).doReadSelectedSync());
15 17 // for(List<Object> row: data) {
16 18 // for(Object item: row) {
... ...