无法读取php excel 2003文件

时间:2015-10-23 11:42:11

标签: php phpexcel

我有这个代码用于阅读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');

2 个答案:

答案 0 :(得分:0)

我认为你应该使用

 PHPExcel_IOFactory::createReader('Excel5');

PHPExcel_IOFactory::createReader('Excel2003XML');

而不是

 PHPExcel_IOFactory::createReader('Excel2007');

这取决于你的xls文件。您可以阅读更多详细信息here PHPExcel Docs。

答案 1 :(得分:0)

$inputFileType = PHPExcel_IOFactory::identify($inputFile);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

phpexcel标识文件的类型。