@@ -157,64 +157,67 @@ public function listWorksheetInfo(string $filename): array
157157
158158 // Step into the first level of content of the XML
159159 $ xml ->read ();
160+ $ tableVisibility = [];
161+ $ lastTableStyle = '' ;
162+
160163 while ($ xml ->read ()) {
161- // Quickly jump through to the office:body node
162- while (self ::getXmlName ($ xml ) !== 'office:body ' ) {
163- if ($ xml ->isEmptyElement ) {
164- $ xml ->read ();
165- } else {
166- $ xml ->next ();
164+ if (self ::getXmlName ($ xml ) === 'style:style ' ) {
165+ $ styleType = $ xml ->getAttribute ('style:family ' );
166+ if ($ styleType === 'table ' ) {
167+ $ lastTableStyle = $ xml ->getAttribute ('style:name ' );
167168 }
168- }
169- // Now read each node until we find our first table:table node
170- while ($ xml ->read ()) {
171- if (self ::getXmlName ($ xml ) == 'table:table ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
172- $ worksheetNames [] = $ xml ->getAttribute ('table:name ' );
173-
174- $ tmpInfo = [
175- 'worksheetName ' => $ xml ->getAttribute ('table:name ' ),
176- 'lastColumnLetter ' => 'A ' ,
177- 'lastColumnIndex ' => 0 ,
178- 'totalRows ' => 0 ,
179- 'totalColumns ' => 0 ,
180- ];
181-
182- // Loop through each child node of the table:table element reading
183- $ currCells = 0 ;
184- do {
169+ } elseif (self ::getXmlName ($ xml ) === 'style:table-properties ' ) {
170+ $ visibility = $ xml ->getAttribute ('table:display ' );
171+ $ tableVisibility [$ lastTableStyle ] = ($ visibility === 'false ' ) ? Worksheet::SHEETSTATE_HIDDEN : Worksheet::SHEETSTATE_VISIBLE ;
172+ } elseif (self ::getXmlName ($ xml ) == 'table:table ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
173+ $ worksheetNames [] = $ xml ->getAttribute ('table:name ' );
174+
175+ $ styleName = $ xml ->getAttribute ('table:style-name ' ) ?? '' ;
176+ $ visibility = $ tableVisibility [$ styleName ] ?? '' ;
177+ $ tmpInfo = [
178+ 'worksheetName ' => $ xml ->getAttribute ('table:name ' ),
179+ 'lastColumnLetter ' => 'A ' ,
180+ 'lastColumnIndex ' => 0 ,
181+ 'totalRows ' => 0 ,
182+ 'totalColumns ' => 0 ,
183+ 'sheetState ' => $ visibility ,
184+ ];
185+
186+ // Loop through each child node of the table:table element reading
187+ $ currCells = 0 ;
188+ do {
189+ $ xml ->read ();
190+ if (self ::getXmlName ($ xml ) == 'table:table-row ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
191+ $ rowspan = $ xml ->getAttribute ('table:number-rows-repeated ' );
192+ $ rowspan = empty ($ rowspan ) ? 1 : $ rowspan ;
193+ $ tmpInfo ['totalRows ' ] += $ rowspan ;
194+ $ tmpInfo ['totalColumns ' ] = max ($ tmpInfo ['totalColumns ' ], $ currCells );
195+ $ currCells = 0 ;
196+ // Step into the row
185197 $ xml ->read ();
186- if (self ::getXmlName ($ xml ) == 'table:table-row ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
187- $ rowspan = $ xml ->getAttribute ('table:number-rows-repeated ' );
188- $ rowspan = empty ($ rowspan ) ? 1 : $ rowspan ;
189- $ tmpInfo ['totalRows ' ] += $ rowspan ;
190- $ tmpInfo ['totalColumns ' ] = max ($ tmpInfo ['totalColumns ' ], $ currCells );
191- $ currCells = 0 ;
192- // Step into the row
193- $ xml ->read ();
194- do {
195- $ doread = true ;
196- if (self ::getXmlName ($ xml ) == 'table:table-cell ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
197- if (!$ xml ->isEmptyElement ) {
198- ++$ currCells ;
199- $ xml ->next ();
200- $ doread = false ;
201- }
202- } elseif (self ::getXmlName ($ xml ) == 'table:covered-table-cell ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
203- $ mergeSize = $ xml ->getAttribute ('table:number-columns-repeated ' );
204- $ currCells += (int ) $ mergeSize ;
198+ do {
199+ $ doread = true ;
200+ if (self ::getXmlName ($ xml ) == 'table:table-cell ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
201+ if (!$ xml ->isEmptyElement ) {
202+ ++$ currCells ;
203+ $ xml ->next ();
204+ $ doread = false ;
205205 }
206- if ($ doread ) {
207- $ xml ->read ();
208- }
209- } while (self ::getXmlName ($ xml ) != 'table:table-row ' );
210- }
211- } while (self ::getXmlName ($ xml ) != 'table:table ' );
206+ } elseif (self ::getXmlName ($ xml ) == 'table:covered-table-cell ' && $ xml ->nodeType == XMLReader::ELEMENT ) {
207+ $ mergeSize = $ xml ->getAttribute ('table:number-columns-repeated ' );
208+ $ currCells += (int ) $ mergeSize ;
209+ }
210+ if ($ doread ) {
211+ $ xml ->read ();
212+ }
213+ } while (self ::getXmlName ($ xml ) != 'table:table-row ' );
214+ }
215+ } while (self ::getXmlName ($ xml ) != 'table:table ' );
212216
213- $ tmpInfo ['totalColumns ' ] = max ($ tmpInfo ['totalColumns ' ], $ currCells );
214- $ tmpInfo ['lastColumnIndex ' ] = $ tmpInfo ['totalColumns ' ] - 1 ;
215- $ tmpInfo ['lastColumnLetter ' ] = Coordinate::stringFromColumnIndex ($ tmpInfo ['lastColumnIndex ' ] + 1 );
216- $ worksheetInfo [] = $ tmpInfo ;
217- }
217+ $ tmpInfo ['totalColumns ' ] = max ($ tmpInfo ['totalColumns ' ], $ currCells );
218+ $ tmpInfo ['lastColumnIndex ' ] = $ tmpInfo ['totalColumns ' ] - 1 ;
219+ $ tmpInfo ['lastColumnLetter ' ] = Coordinate::stringFromColumnIndex ($ tmpInfo ['lastColumnIndex ' ] + 1 );
220+ $ worksheetInfo [] = $ tmpInfo ;
218221 }
219222 }
220223
0 commit comments