Gary Croxford
asked on
Php read spreadsheet into an array
Hello,
I need to extract data from a spreadsheet (xlsx) into an array. I am struggling with phpspreadsheet and really need some help.
My first attempt returns the number of rows in the first sheet of the workbook but when I try to display the contents to the screen in a table the code falls over with http 500 error - I can't see why and don't know how to capture the cause of the error.
require '../../../../composer/vend or/autoloa d.php';
use phpoffice\phpspreadsheet\s preadsheet ;
use phpoffice\phpspreadsheet\w riter\xlsx ;
$xlfile = 'ExcelTest.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\ IOFactory: :load($xlf ile);
$xls_data = $spreadsheet->getActiveShe et()->toAr ray(null, true, true, true);
$nrows = count($xls_data);
echo '<h2> No. Rows: ' . $nrows . '</h2>'; //Code works to here
/*
// If I include this the whole thing falls over
echo '<table>';
foreach ($xls_data[0] as $column){
echo '<tr><td>' . $column . '</td></tr>';
}
echo '</table>';
*/
ExcelTest.xlsx
CESTrack_2.php
I need to extract data from a spreadsheet (xlsx) into an array. I am struggling with phpspreadsheet and really need some help.
My first attempt returns the number of rows in the first sheet of the workbook but when I try to display the contents to the screen in a table the code falls over with http 500 error - I can't see why and don't know how to capture the cause of the error.
require '../../../../composer/vend
use phpoffice\phpspreadsheet\s
use phpoffice\phpspreadsheet\w
$xlfile = 'ExcelTest.xlsx';
$spreadsheet = \PhpOffice\PhpSpreadsheet\
$xls_data = $spreadsheet->getActiveShe
$nrows = count($xls_data);
echo '<h2> No. Rows: ' . $nrows . '</h2>'; //Code works to here
/*
// If I include this the whole thing falls over
echo '<table>';
foreach ($xls_data[0] as $column){
echo '<tr><td>' . $column . '</td></tr>';
}
echo '</table>';
*/
ExcelTest.xlsx
CESTrack_2.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER