[英]Cant read php excel 2003 file
I have this code that I use to read Excel 2007
file. 我有用于读取Excel 2007
文件的这段代码。
<?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. 但是我需要阅读一个Excel 2003
文件。 When I change the code I get error saying that: 当我更改代码时,出现错误消息:
Fatal error: Class 'PHPExcel_Reader_Excel2003' not found in ... 致命错误:找不到类'PHPExcel_Reader_Excel2003'
Change code: 更改代码:
$objReader = PHPExcel_IOFactory::createReader('Excel2003');
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. 这取决于您的xls文件。 You can read more details here PHPExcel Docs. 您可以在此处阅读更多详细信息PHPExcel文档。
$inputFileType = PHPExcel_IOFactory::identify($inputFile);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
Make phpexcel
identify what type of your file. 使phpexcel
识别文件的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.