php擷取excel檔案資料

來源:互聯網
上載者:User

標籤:anr   class   目錄   輸出   font   字元   turn   pre   logs   

很簡單就可以實現,下面為大家簡單介紹下

1、下載PHPExcel類,是一個檔案夾,還得有一個檔案PHPExcel.php,兩個在同級目錄

 

 1 require __DIR__ . ‘./PHPExcel/IOFactory.php‘; 2  3         $PHPReader = new \PHPExcel_Reader_Excel2007(); 4  5         //判斷檔案類型 6         if (!$PHPReader->canRead($filePath)) { 7             $PHPReader = new \PHPExcel_Reader_Excel5(); 8  9             if (!$PHPReader->canRead($filePath)) {10                 echo ‘no Excel‘;11                 return false;12             }13         }14 15         $PHPExcel = $PHPReader->load($filePath);16         /**讀取excel檔案中的第一個工作表*/17 18         $currentSheet = $PHPExcel->getSheet(0);19         /**取得最大的列號*/20 21         $allColumn = $currentSheet->getHighestColumn();22         /**取得一共有多少行*/23 24         $allRow = $currentSheet->getHighestRow();25 26         /**從第1行開始輸出*/27         for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {28 29             /**從第A列開始輸出*/30             for ($currentColumn = ‘A‘; $currentColumn <= $allColumn; $currentColumn++) {31                 $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();32                 /**ord()將字元轉為十進位數*/33                 $date[$currentRow - 1][] = $val;34             }35 36         }37         return $date;

 

php擷取excel檔案資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.