1
1
package com .monitorjbl .xlsx .impl ;
2
2
3
3
import com .monitorjbl .xlsx .exceptions .CloseException ;
4
- import org .apache .poi .openxml4j .opc .OPCPackage ;
5
4
import org .apache .poi .ss .usermodel .BuiltinFormats ;
6
5
import org .apache .poi .ss .usermodel .DataFormatter ;
7
6
import org .apache .poi .ss .usermodel .Row ;
29
28
import java .io .InputStream ;
30
29
import java .nio .file .Files ;
31
30
import java .util .ArrayList ;
31
+ import java .util .HashSet ;
32
32
import java .util .Iterator ;
33
33
import java .util .List ;
34
+ import java .util .Set ;
34
35
35
36
public class StreamingSheetReader implements Iterable <Row > {
36
37
private static final Logger log = LoggerFactory .getLogger (StreamingSheetReader .class );
@@ -39,6 +40,7 @@ public class StreamingSheetReader implements Iterable<Row> {
39
40
private final StylesTable stylesTable ;
40
41
private final XMLEventReader parser ;
41
42
private final DataFormatter dataFormatter = new DataFormatter ();
43
+ private final Set <Integer > hiddenColumns = new HashSet <>();
42
44
43
45
private int rowCacheSize ;
44
46
private List <Row > rowCache = new ArrayList <>();
@@ -89,8 +91,22 @@ private void handleEvent(XMLEvent event) throws SAXException {
89
91
String tagLocalName = startElement .getName ().getLocalPart ();
90
92
91
93
if ("row" .equals (tagLocalName )) {
92
- Attribute rowIndex = startElement .getAttributeByName (new QName ("r" ));
93
- currentRow = new StreamingRow (Integer .parseInt (rowIndex .getValue ()) - 1 );
94
+ Attribute rowNumAttr = startElement .getAttributeByName (new QName ("r" ));
95
+ Attribute isHiddenAttr = startElement .getAttributeByName (new QName ("hidden" ));
96
+ int rowIndex = Integer .parseInt (rowNumAttr .getValue ()) - 1 ;
97
+ boolean isHidden = isHiddenAttr != null && "1" .equals (isHiddenAttr .getValue ());
98
+ currentRow = new StreamingRow (rowIndex , isHidden );
99
+ } else if ("col" .equals (tagLocalName )) {
100
+ Attribute isHiddenAttr = startElement .getAttributeByName (new QName ("hidden" ));
101
+ boolean isHidden = isHiddenAttr != null && "1" .equals (isHiddenAttr .getValue ());
102
+ if (isHidden ) {
103
+ Attribute minAttr = startElement .getAttributeByName (new QName ("min" ));
104
+ Attribute maxAttr = startElement .getAttributeByName (new QName ("max" ));
105
+ int min = Integer .parseInt (minAttr .getValue ()) - 1 ;
106
+ int max = Integer .parseInt (maxAttr .getValue ()) - 1 ;
107
+ for (int columnIndex = min ; columnIndex <= max ; columnIndex ++)
108
+ hiddenColumns .add (columnIndex );
109
+ }
94
110
} else if ("c" .equals (tagLocalName )) {
95
111
Attribute ref = startElement .getAttributeByName (new QName ("r" ));
96
112
@@ -135,6 +151,19 @@ private void handleEvent(XMLEvent event) throws SAXException {
135
151
}
136
152
}
137
153
154
+ /**
155
+ * Get the hidden state for a given column
156
+ *
157
+ * @param columnIndex - the column to set (0-based)
158
+ * @return hidden - <code>false</code> if the column is visible
159
+ */
160
+ boolean isColumnHidden (int columnIndex ) {
161
+ if (rowCacheIterator == null ) {
162
+ getRow ();
163
+ }
164
+ return hiddenColumns .contains (columnIndex );
165
+ }
166
+
138
167
/**
139
168
* Read the numeric format string out of the styles table for this cell. Stores
140
169
* the result in the Cell.
0 commit comments