I can't understand, how i can extract data (array) from named spreadsheet using phpspreadsheet lib, for ex, i have workbook with many named spreadsheet (fisrt,second etc), I get array, with all named spreadsheets:
Code:
$inputFileName = 'uploads/1.xlsx';
$inputFileType = IOFactory::identify($inputFileName);
$reader = IOFactory::createReader($inputFileType);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName);
$worksheetNames = $reader->listWorksheetNames($inputFileName);
echo "<pre>";
print_r($worksheetNames);
echo "</pre>";
output:
Array
(
[0] => firts
[1] => second
[2] => third
)
By using this example, I can get all data of active (first) spreadsheet:
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
print_r($sheetData);
but how I can get for specific one, "second" spreadsheet data?
You can use
for to get a list of all sheets or you can iterate
For more information, check the link here.