I want to read an xlsx
file that was created in Microsoft Excel, but when I run the following code...
$Source_File = \"test.xlsx\";
$Spreadsheet
From my understanding, you are missing a piece. Why don't you first create a reader and then load the file.
Try the following code. It can identify the extension and create the reader of that type accordingly.
$inputFileName = "Text.xlsx";
/** Identify the type of $inputFileName **/
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
/** Convert Spreadsheet Object to an Array for ease of use **/
$schdeules = $spreadsheet->getActiveSheet()->toArray();
Now you can simply run a foreach loop on the result array.
foreach( $schdeules as $single_schedule )
{
echo '';
foreach( $single_schedule as $single_item )
{
echo '' . $single_item . '
';
}
echo '';
}
This is tested and working code.