/*導出記錄*/
function actionExcelSign2(){
header('Content-Type:text/html; charset=utf-8');
$signM = M("model");
// 查詢
$rows = $signM->select();
Vendor('PHPExcel.PHPExcel');
//建立對象
$objPHPExcel = new \PHPExcel();
//設置屬性
$objPHPExcel->getProperties()
->setCreator("WOLF")
->setLastModifiedBy("WOLF")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
//垂直居中
$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
//自動填充到頁面的寬度
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth('20');
//填充表格
$objActSheet = $objPHPExcel->setActiveSheetIndex(0); //填充表頭
$objActSheet->setCellValue('B1','用戶');
$objActSheet->setCellValue('C1','訂單號');
$objActSheet->setCellValue('D1','收貨人省份證');
$objActSheet->setCellValue('E1','商品名稱');
//填充內容
for($i=0; $i<count($rows); $i++){
$key = $i+2;
$objActSheet->setCellValue('B'.$key, $rows[$i]['user_id']);
$objActSheet->setCellValue('C'.$key, $rows[$i]['order_no'].' ');
$objActSheet->setCellValue('D'.$key, $rows[$i]['cardno'].' ');
$objActSheet->setCellValue('E'.$key, $rows[$i]['productname']);
}
//輸出
$objPHPExcel->getActiveSheet()->setTitle('訂單列表');
$objPHPExcel->setActiveSheetIndex(0);
$day = date("m-d");
$filename = '訂單列表.xls';
ob_end_clean();//清除緩衝區,避免亂碼
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
$objWriter->save('php://output');
exit;
}