[英]Cant read php excel 2003 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";
}
?>
但是我需要閱讀一個Excel 2003
文件。 當我更改代碼時,出現錯誤消息:
致命錯誤:找不到類'PHPExcel_Reader_Excel2003'
更改代碼:
$objReader = PHPExcel_IOFactory::createReader('Excel2003');
我認為你應該使用
PHPExcel_IOFactory::createReader('Excel5');
要么
PHPExcel_IOFactory::createReader('Excel2003XML');
代替
PHPExcel_IOFactory::createReader('Excel2007');
這取決於您的xls文件。 您可以在此處閱讀更多詳細信息PHPExcel文檔。
$inputFileType = PHPExcel_IOFactory::identify($inputFile);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
使phpexcel
識別文件的類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.