Commit 05ceff0fd4311367930cadee67c84dbb3f3098f9
1 parent
21fd3715
Exists in
master
1.tempmodify
Showing
5 changed files
with
28 additions
and
9 deletions
Show diff stats
src/main/java/com/taover/easyexcel/analysis/ExcelAnalyserImpl.java
@@ -111,6 +111,7 @@ public class ExcelAnalyserImpl implements ExcelAnalyser { | @@ -111,6 +111,7 @@ public class ExcelAnalyserImpl implements ExcelAnalyser { | ||
111 | } | 111 | } |
112 | analysisContext.readWorkbookHolder().setParameterSheetDataList(readSheetList); | 112 | analysisContext.readWorkbookHolder().setParameterSheetDataList(readSheetList); |
113 | analysisContext.readWorkbookHolder().setReadAll(readAll); | 113 | analysisContext.readWorkbookHolder().setReadAll(readAll); |
114 | + analysisContext.readWorkbookHolder().setReadJustSelected(false); | ||
114 | for(ReadSheet item: readSheetList) { | 115 | for(ReadSheet item: readSheetList) { |
115 | if(item.getSheetSelected()) { | 116 | if(item.getSheetSelected()) { |
116 | analysisContext.readWorkbookHolder().setReadJustSelected(true); | 117 | analysisContext.readWorkbookHolder().setReadJustSelected(true); |
src/main/java/com/taover/easyexcel/analysis/v07/XlsxSaxAnalyser.java
@@ -197,12 +197,16 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | @@ -197,12 +197,16 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { | ||
197 | for (ReadSheet readSheet : sheetList) { | 197 | for (ReadSheet readSheet : sheetList) { |
198 | readSheet = SheetUtils.match(readSheet, xlsxReadContext); | 198 | readSheet = SheetUtils.match(readSheet, xlsxReadContext); |
199 | if (readSheet != null) { | 199 | if (readSheet != null) { |
200 | - xlsxReadContext.currentSheet(readSheet); | ||
201 | - parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext)); | ||
202 | - // Read comments | ||
203 | - readComments(readSheet); | ||
204 | - // The last sheet is read | ||
205 | - xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext); | 200 | + try { |
201 | + xlsxReadContext.currentSheet(readSheet); | ||
202 | + parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext)); | ||
203 | + // Read comments | ||
204 | + readComments(readSheet); | ||
205 | + // The last sheet is read | ||
206 | + xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext); | ||
207 | + }catch (Exception e) { | ||
208 | + e.printStackTrace(); | ||
209 | + } | ||
206 | } | 210 | } |
207 | } | 211 | } |
208 | } | 212 | } |
src/main/java/com/taover/easyexcel/analysis/v07/handlers/sax/XlsxRowHandler.java
@@ -23,7 +23,7 @@ import com.taover.easyexcel.context.xlsx.XlsxReadContext; | @@ -23,7 +23,7 @@ import com.taover.easyexcel.context.xlsx.XlsxReadContext; | ||
23 | * @author jipengfei | 23 | * @author jipengfei |
24 | */ | 24 | */ |
25 | public class XlsxRowHandler extends DefaultHandler { | 25 | public class XlsxRowHandler extends DefaultHandler { |
26 | - private static final boolean XLSX_DEBUB_PRINT_INFO = true; | 26 | + private static final boolean XLSX_DEBUB_PRINT_INFO = false; |
27 | private XlsxReadContext xlsxReadContext; | 27 | private XlsxReadContext xlsxReadContext; |
28 | private static final Map<String, XlsxTagHandler> XLSX_CELL_HANDLER_MAP = new HashMap<String, XlsxTagHandler>(32); | 28 | private static final Map<String, XlsxTagHandler> XLSX_CELL_HANDLER_MAP = new HashMap<String, XlsxTagHandler>(32); |
29 | 29 | ||
@@ -62,7 +62,18 @@ public class XlsxRowHandler extends DefaultHandler { | @@ -62,7 +62,18 @@ public class XlsxRowHandler extends DefaultHandler { | ||
62 | public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { | 62 | public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { |
63 | if(XLSX_DEBUB_PRINT_INFO) { | 63 | if(XLSX_DEBUB_PRINT_INFO) { |
64 | this.printElement("startElement", uri, localName, name, attributes); | 64 | this.printElement("startElement", uri, localName, name, attributes); |
65 | - } | 65 | + } |
66 | + | ||
67 | + //whether just read selected sheet | ||
68 | + Boolean readJustSelected = this.xlsxReadContext.readWorkbookHolder().getReadJustSelected(); | ||
69 | + if(ExcelXmlConstants.SHEET_VIEW_TAG.equals(name) | ||
70 | + && readJustSelected != null | ||
71 | + && readJustSelected | ||
72 | + && !"1".equals(attributes.getValue("tabSelected"))) { | ||
73 | + //throw new SAXException("not selected sheet, just read selected sheet"); | ||
74 | + //return; | ||
75 | + } | ||
76 | + | ||
66 | XlsxTagHandler handler = XLSX_CELL_HANDLER_MAP.get(name); | 77 | XlsxTagHandler handler = XLSX_CELL_HANDLER_MAP.get(name); |
67 | if (handler == null | 78 | if (handler == null |
68 | || !handler.support(xlsxReadContext) | 79 | || !handler.support(xlsxReadContext) |
src/main/java/com/taover/easyexcel/constant/ExcelXmlConstants.java
@@ -4,6 +4,9 @@ package com.taover.easyexcel.constant; | @@ -4,6 +4,9 @@ package com.taover.easyexcel.constant; | ||
4 | * @author jipengfei | 4 | * @author jipengfei |
5 | */ | 5 | */ |
6 | public class ExcelXmlConstants { | 6 | public class ExcelXmlConstants { |
7 | + public static final String SHEET_VIEW_TAG = "sheetView"; | ||
8 | + public static final String X_SHEET_VIEW_TAG = "x:sheetView"; | ||
9 | + | ||
7 | public static final String DIMENSION_TAG = "dimension"; | 10 | public static final String DIMENSION_TAG = "dimension"; |
8 | public static final String ROW_TAG = "row"; | 11 | public static final String ROW_TAG = "row"; |
9 | public static final String CELL_FORMULA_TAG = "f"; | 12 | public static final String CELL_FORMULA_TAG = "f"; |
src/test/java/com/taover/easyexcel/test/demo/read/ReadTest.java
@@ -253,7 +253,7 @@ public class ReadTest { | @@ -253,7 +253,7 @@ public class ReadTest { | ||
253 | // } | 253 | // } |
254 | 254 | ||
255 | // 这里 也可以不指定class,返回一个list,然后读取第一个sheet 同步读取会自动finish | 255 | // 这里 也可以不指定class,返回一个list,然后读取第一个sheet 同步读取会自动finish |
256 | - List<Map<Integer, String>> listMap = EasyExcel.read("D://demo.xlsx").sheet().doReadSync(); | 256 | + List<Map<Integer, String>> listMap = EasyExcel.read("D://demo.xlsx").sheet(true).doReadSync(); |
257 | for (Map<Integer, String> data : listMap) { | 257 | for (Map<Integer, String> data : listMap) { |
258 | // 返回每条数据的键值对 表示所在的列 和所在列的值 | 258 | // 返回每条数据的键值对 表示所在的列 和所在列的值 |
259 | LOGGER.info("读取到数据:{}", JSON.toJSONString(data)); | 259 | LOGGER.info("读取到数据:{}", JSON.toJSONString(data)); |