File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,14 @@ $rows = SimpleExcelReader::create($pathToXlsx)
125
125
->getRows();
126
126
```
127
127
128
+ You can also retrieve all sheet names in a document using the ` getSheetNames() ` method.
129
+
130
+ ``` php
131
+ $sheets = SimpleExcelReader::create($pathToXlsx)
132
+ ->getSheetNames();
133
+ ```
134
+
135
+
128
136
With multiple spreadsheets, you can too select the sheet you want to use with the ` fromSheetName() ` method to select by name.
129
137
130
138
``` php
Original file line number Diff line number Diff line change @@ -187,6 +187,21 @@ public function take(int $count): SimpleExcelReader
187
187
return $ this ;
188
188
}
189
189
190
+ public function getSheetNames (): array
191
+ {
192
+ $ this ->setReader ();
193
+
194
+ $ this ->reader ->open ($ this ->path );
195
+
196
+ $ sheets = [];
197
+
198
+ foreach ($ this ->reader ->getSheetIterator () as $ sheet ) {
199
+ $ sheets [] = $ sheet ->getName ();
200
+ }
201
+
202
+ return $ sheets ;
203
+ }
204
+
190
205
public function hasSheet (string $ sheetName ): bool
191
206
{
192
207
$ this ->setReader ();
Original file line number Diff line number Diff line change @@ -566,6 +566,17 @@ function () {
566
566
]);
567
567
});
568
568
569
+ it ('can get multiple sheet names ' , function () {
570
+ $ reader = SimpleExcelReader::create (getStubPath ('multiple_sheets.xlsx ' ));
571
+
572
+ expect (
573
+ $ reader ->getSheetNames ()
574
+ )->toEqual ([
575
+ 0 => 'sheet1 ' ,
576
+ 1 => 'sheet2 ' ,
577
+ ]);
578
+ });
579
+
569
580
it ('will not open non-existing sheets ' , function () {
570
581
SimpleExcelReader::create (getStubPath ('multiple_sheets.xlsx ' ))
571
582
->fromSheet (3 )
You can’t perform that action at this time.
0 commit comments