简体   繁体   中英

Cant read php excel 2003 file

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');

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.

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

Make phpexcel identify what type of your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM