11package com .monitorjbl .xlsx .impl ;
22
33import com .monitorjbl .xlsx .exceptions .CloseException ;
4- import org .apache .poi .openxml4j .opc .OPCPackage ;
54import org .apache .poi .ss .usermodel .BuiltinFormats ;
65import org .apache .poi .ss .usermodel .DataFormatter ;
76import org .apache .poi .ss .usermodel .Row ;
2928import java .io .InputStream ;
3029import java .nio .file .Files ;
3130import java .util .ArrayList ;
31+ import java .util .HashSet ;
3232import java .util .Iterator ;
3333import java .util .List ;
34+ import java .util .Set ;
3435
3536public class StreamingSheetReader implements Iterable <Row > {
3637 private static final Logger log = LoggerFactory .getLogger (StreamingSheetReader .class );
@@ -39,6 +40,7 @@ public class StreamingSheetReader implements Iterable<Row> {
3940 private final StylesTable stylesTable ;
4041 private final XMLEventReader parser ;
4142 private final DataFormatter dataFormatter = new DataFormatter ();
43+ private final Set <Integer > hiddenColumns = new HashSet <>();
4244
4345 private int rowCacheSize ;
4446 private List <Row > rowCache = new ArrayList <>();
@@ -89,8 +91,22 @@ private void handleEvent(XMLEvent event) throws SAXException {
8991 String tagLocalName = startElement .getName ().getLocalPart ();
9092
9193 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+ }
94110 } else if ("c" .equals (tagLocalName )) {
95111 Attribute ref = startElement .getAttributeByName (new QName ("r" ));
96112
@@ -135,6 +151,19 @@ private void handleEvent(XMLEvent event) throws SAXException {
135151 }
136152 }
137153
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+
138167 /**
139168 * Read the numeric format string out of the styles table for this cell. Stores
140169 * the result in the Cell.
0 commit comments