使用PHPExcel讀取xls/xlsx文件
require_once( LIB.'Excel/excel/PHPExcel/IOFactory.php');function readexcel( $filePath) { $PHPReader = new PHPExcel_Reader_Excel5(); if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}$PHPExcel = $PHPReader->load($filePath);
$currentSheet = $PHPExcel->getSheet(0); /*取得一共有多少列/
$allColumn = $currentSheet->getHighestColumn(); /*取得一共有多少行/
$allRow = $currentSheet->getHighestRow();
$all = array(); for( $currentRow = 1 ; $currentRow <= $allRow ; $currentRow++){
$flag = 0; $col = array(); for($currentColumn='A'; getascii($currentColumn) <= getascii($allColumn) ; $currentColumn++){ $address = $currentColumn.$currentRow; $string = $currentSheet->getCell($address)->getValue(); $col[$flag] = $string; $flag++; } $all[] = $col;
} return $all; }</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!