[982]PHP網站開發 進階應用技巧
<?php
//關閉PHP錯誤報告
error_reporting(E_ALL);
//引入 PHPExcel 物件庫
require_once 'excel/PHPExcel.php';
//引入 PHPExcel_IOFactory 物件庫
require_once 'excel/PHPExcel/IOFactory.php';
//實體化Excel
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0); //設定預設顯示的工作表
$objActSheet = $objPHPExcel->getActiveSheet(); //指定預設工作表為 $objActSheet
$objActSheet->setTitle("個人通訊錄"); //設定標題
for($i=1;$i<=12;$i++){
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($i);
$var_name="objActSheet{$i}";
$$var_name = $objPHPExcel->getActiveSheet();
$$var_name->setTitle("{$i}月份收支簿");
}
$objPHPExcel->setActiveSheetIndex(0);
//輸出
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=檔名'.date("YmdHis"));
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>