用PHPExcel類讀取excel文件的內容


這里對PHPExcel類不做介紹,有興趣的朋友可以自己查閱資料

在classes文件夾下有個PHPExcel.php文件,這個文件是這個類庫的主要入口文件,在用之前,要引入這個類

其他的類,在此類中會自動加載

 1       //建立reader對象 ,分別用兩個不同的類對象讀取2007和2003版本的excel文件
 2         $PHPReader = new PHPExcel_Reader_Excel2007();
 3         if( ! $PHPReader->canRead($filePath))
 4         {
 5             $PHPReader = new PHPExcel_Reader_Excel5();
 6             if( ! $PHPReader->canRead($filePath)){
 7                 echo 'no Excel';
 8                 return ;
 9             }
10         }
11 
12         $PHPExcel = $PHPReader->load($filePath); //讀取文件
13         $currentSheet = $PHPExcel->getSheet(0); //讀取第一個工作簿
14         $allColumn = $currentSheet->getHighestColumn(); // 所有列數
15         $allRow = $currentSheet->getHighestRow(); // 所有行數
16     
17         $data = array(); //下面是讀取想要獲取的列的內容
18         for ($rowIndex = 2; $rowIndex <= $allRow; $rowIndex++)
19         {
20             $data[] = array(
21                 'id' => $cell = $currentSheet->getCell('A'.$rowIndex)->getValue(),
22                 'score' => $cell = $currentSheet->getCell('H'.$rowIndex)->getValue(),
23                 'ranking' => $cell = $currentSheet->getCell('I'.$rowIndex)->getValue(),
24             );
25         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM