PHPExcel套件最後一版是2015年寫的,目前已不再更新。
https://github.com/PHPOffice/PHPExcel
為了因應越來越複雜的Excel版本,得找找有沒有可以替代的套件。
這是PHPExcel的後續套件PHPSpreadSheet
https://github.com/PHPOffice/PhpSpreadsheet/
徐嘉裕(Neil Hsu)的工作心得網誌!
唯一比較麻煩的是使用PhpSpreadsheet要先佈署composer,如果沒佈署composer是沒辦法使用的,還好官方有釋出已經設定好的phpoffice套件可以直接引入使用,省了很多麻煩
https://neohsuxoops.blogspot.com/2020/09/phpspreadsheetphpexcel-xoops.html
PhpSpreadsheet套件下載
https://drive.google.com/file/d/1jw73diWVjbcr1ycY-gtqM2cGfpLp1zS_/view?usp=sharing
下載回來後解壓縮把phpoffice跟PhpSpreadsheet丟到class資料夾中,未來如需更新PhpSpreadsheet可到官網下載最新版覆蓋即可
使用說明https://phpspreadsheet.readthedocs.io/en/latest/
read 範例(php 7.4)( 在php5.6測試有問題)
<?php
include_once 'class/phpoffice/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
//require __DIR__ . '/../Header.php';
//$inputFileName = __DIR__ . '/sampleData/example1.xls';
//$inputFileName = __DIR__ . '/good-example.xlsx';
$inputFileName = __DIR__ . '/1103289.xls';
//$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory to identify the format');
$spreadsheet = IOFactory::load($inputFileName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
//$helper->displayGrid($sheetData);
print_r($sheetData);