Reputation: 2942
I have this code that I use to read Excel 2007
file.
<?php
function load_table(){
require_once('Classes/PHPExcel.php');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(false);
$objPHPExcel = $objReader->load("SampleData.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
echo '<table class="table">' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
echo '<td>';
$first = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
if($first[0] == '='){
echo $objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue();
}
else
echo $first;
echo '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
}
?>
But I need to read an Excel 2003
file. When I change the code I get error saying that:
Fatal error: Class 'PHPExcel_Reader_Excel2003' not found in ...
Change code:
$objReader = PHPExcel_IOFactory::createReader('Excel2003');
Upvotes: 0
Views: 4651
Reputation: 1
$inputFileType = PHPExcel_IOFactory::identify($inputFile);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
Make phpexcel
identify what type of your file.
Upvotes: 0
Reputation: 33
I think you should use
PHPExcel_IOFactory::createReader('Excel5');
or
PHPExcel_IOFactory::createReader('Excel2003XML');
instead of
PHPExcel_IOFactory::createReader('Excel2007');
It's depends your xls file. You can read more details here PHPExcel Docs.
Upvotes: 2