phpをExcelにエクスポート
[PHP]コード
- vendor("PHPExcel176.PHPExcel");
- // 新しい PHPExcel オブジェクトを作成します
- $objPHPExcel = new PHPExcel();
- // プロパティを設定します
- $objPHPExcel->getProperties()->setCreator("ctos ")
- ->setLastModifiedBy("ctos")
- ->setTitle("Office 2007 XLSX テスト ドキュメント")
- ->setSubject("Office 2007 XLSX テスト ドキュメント")
- ->setDescription("次のテスト ドキュメントOffice 2007 XLSX、PHP クラスを使用して生成。")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("テスト結果ファイル");
- //幅を設定
- $objPHPExcel->getActiveSheet( )->getColumnDimension('A')->setWidth(80);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(80);
- $objPHPExcel-> getActiveSheet()->getColumnDimension('C')->setWidth(80);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(80);
- $objPHPExcel- >getActiveSheet()->getColumnDimension('E')->setWidth(80);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(80);
- / /設定行高
- //$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
- //$objPHPExcel->getActiveSheet()->getRowDimension('2 ')->setRowHeight(20);
- //フォントサイズを太字に設定します
- $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
- //$ objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getFont()->setBold(true);
- //$objPHPExcel->getActiveSheet()->getStyle('A2 :F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getBorders()- >getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- //设置水平居中
- //$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()-> ;set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel-> getActiveSheet()->getStyle('B')->getAlignment()->sethorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D')-> getAlignment()->set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //合并cell
- //$objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
- //フォントサイズを太字に設定
- //$objPHPExcel->getActiveSheet()->getDefaultStyle( )->getFont()->setSize(10);
- //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getFont()->setBold(true) ;
- //$objPHPExcel->getActiveSheet()->getStyle('A2:F2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- //$objPHPExcel->getActiveSheet( )->getStyle('A2:F2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);?????????
- $objPHPExcel-> ;getActiveSheet()->getStyle('A1')->getAlignment()->sethorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('A')-> ;getAlignment()->set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->set水平(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->sethorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle(' F')->getAlignment()->sethorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //???セル
- $objPHPExcel->getActiveSheet()->mergeCells('A1:F1');
- / / テーブルヘッダーの内容を設定します
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', iconv("utf-8","gb2312","订单数据汇总 時間:'.date('Y-m-d H :i:s')"))
- ->setCellValue('A2', iconv("utf-8","gb2312","注文ID"))
- ->setCellValue('B2', iconv("utf-8","gb2312","ご注文者様"))
- ->setCellValue('C2', iconv("utf-8","gb2312","お客様名"))
- ->setCellValue('D2', iconv(" utf-8 ","gb2312","注文時間"))
- ->setCellValue('E2', iconv("utf-8","gb2312","必要なモデル"))
- ->setCellValue(' F2 ', iconv("utf-8","gb2312","必要な数量"));
- // その他のグリフ、UTF-8
- for($i=0;$i $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($i+3), iconv("utf-8","gb2312",$OrdersData[$i][' id ']));
- $objPHPExcel->getActiveSheet(0)->setCellValue('B'.($i+3), iconv("utf-8","gb2312",$OrdersData[$i] [ 'reid']));
- $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($i+3), iconv("utf-8","gb2312",$OrdersData[$) i ]['topid']));
- //$objPHPExcel->getActiveSheet(0)->setCellValue('D'.($i+3), iconv('utf-8','gb2312', toDate ($OrdersData[$i]['typename']))); //??????common.php??????
- $objPHPExcel->getActiveSheet(0)->setCellValue (' D'.($i+3), iconv("utf-8","gb2312",$OrdersData[$i]['typename']));
- $objPHPExcel->getActiveSheet(0)-> ;setCellValue ('E'.($i+3), iconv("utf-8","gb2312",$OrdersData[$i]['typelink']));
- $objPHPExcel->getActiveSheet(0) -> ;setCellValue('F'.($i+3), iconv("utf-8","gb2312",$OrdersData[$i]['keyword']));
- //$objPHPExcel-> )->getStyle('A'.($i+3).':F'.($i+3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- / /$ objPHPExcel->getActiveSheet()->getStyle('A'.($i+3).':F'.($i+3))->getBorders()->getAllBorders()-> setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- //$objPHPExcel->getActiveSheet()->getRowDimension($i+3)->setRowHeight(16);
- }
- // シート
- $objPHPExcel->getActiveSheet ()->setTitle( iconv("utf-8","gb2312",'Order Summary Table'));
- // アクティブ シート インデックスを最初のシートに設定すると、Excel はこれを最初のシートとして開きます
- $objPHPExcel ->setActiveSheetIndex(0);
- // Excel ヘッダー パラメーター
- header('Content-Type: application/vnd.ms-excel; charset=utf-8');
- header('Content-Type: application/force- download');
- header('Content-Type: application/octet-stream');
- header('Content-Type: application/download');
- //header('Content-type:charset=utf- 8) ;
- //header('Content-Transfer-Encoding: utf-8');
- header('Content-Disposition:attachment;filename='.iconv("utf-8","gb2312","注文概要 ". date('Ymd-His').".xls")); //日付はファイル名のサフィックスです
- //header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'excel5'); //excel5 は xls 形式、excel2007 は xlsx 形式です
- $objWriter->save('php://output');
コードをコピーします
|