很簡單就可以實作,下面為大家簡單介紹下
1、下載下傳PHPExcel類,是一個檔案夾,還得有一個檔案PHPExcel.php,兩個在同級目錄
require __DIR__ . './PHPExcel/IOFactory.php';
$PHPReader = new \PHPExcel_Reader_Excel2007();
//判斷檔案類型
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
echo 'no Excel';
return false;
}
}
$PHPExcel = $PHPReader->load($filePath);
$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
$date[$currentRow - 1][] = $val;
}
}
return $date;
以上就是本文的全部内容,希望本文的内容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支援腳本之家!