官方網站:http://www.codeplex.com/PHPExcel/
以下是一簡單範例及說明:
PHP程式碼
//引入PHPExcel函式庫
require_once("phpexcel/Classes/PHPExcel.php");
require_once("phpexcel/Classes/PHPExcel/IOFactory.php");
require_once("phpexcel/Classes/PHPExcel/Reader/Excel5.php");
//讀取舊版 excel 檔案
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);
//檔案名稱
$objPHPExcel = $objReader->load('xxx.xls');
$currentSheet = $objPHPExcel->getSheet(0);//讀取第一個工作表(編號從 0 開始)
$allLine = array($currentSheet->getHighestRow());//取得總列數
for($excel_line = 1;$excel_line<=$allLine;$excel_line++)
{
echo $currentSheet->getCell("A{$excel_line}")->getValue();
echo $currentSheet->getCell("B{$excel_line}")->getValue();
echo $currentSheet->getCell("C{$excel_line}")->getValue();
echo $currentSheet->getCell("D{$excel_line}")->getValue();
echo $currentSheet->getCell("E{$excel_line}")->getValue();
}
//清空記憶體
unset($objReader);
unset($objPHPExcel);
相關文章:
[PHP]利用PHPExcel函式庫產生Excel檔

0 意見:
張貼留言