評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]
利用PHPEXCEL 產生EXCEL 檔
php部份
include('Classes/PHPExcel.php');
require_once('Classes/PHPExcel/IOFactory.php');
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sql = "SELECT * FROM `XXX` ";
$i=2;
$no=0;
foreach ( $db->query($sql) as $row){
$no+=1;
$objPHPExcel->getActiveSheet()->setTitle('TAB標題');
$objPHPExcel->getActiveSheet()->setCellValue('A1','流水號');
$objPHPExcel->getActiveSheet()->setCellValue('B1','欄位一');
$objPHPExcel->getActiveSheet()->setCellValue('C1','欄位二');
$objPHPExcel->getActiveSheet()->setCellValue('D1','欄位三');
$objPHPExcel->getActiveSheet()->setCellValue('E1','欄位四');
$objPHPExcel->getActiveSheet()->setCellValue('F1','欄位五');
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$no);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$row['欄位一']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$row['欄位二']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$row['欄位三']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$row['欄位四']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$row['欄位五']);
$i+=1;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('export/export_abc.xlsx');//
header('Location:export/export_abc.xlsx');
exit;
?>
html部份
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
評等結果
點擊便能為這篇文章進行評等!
[評等總次數: 0,平均評等: 0]