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("PHP 클래스를 사용하여 생성된 Office 2007 XLSX용 테스트 문서.")
- ->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()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()-> setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(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->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()->setHorizontal(PHPExcel_Style_Alignment:: HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(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);
- //???cell
- $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->getActiveSheet()->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",' 주문 요약 테이블')) ;
- // 활성 시트 인덱스를 첫 번째 시트로 설정하여 Excel에서 이를 첫 번째 시트로 엽니다.
- $objPHPExcel->setActiveSheetIndex(0);
- // Excel 헤더 매개변수
- header(' 콘텐츠 유형: 애플리케이션/vnd.ms-excel; charset=utf-8');
- header('콘텐츠 유형: 애플리케이션/강제-다운로드');
- 헤더(' 콘텐츠 유형: 애플리케이션/ 옥텟 스트림');
- header('콘텐츠 유형: 애플리케이션/다운로드');
- //header('콘텐츠 유형:charset=utf-8);
- //header('콘텐츠 -전송 인코딩: utf-8');
- header('콘텐츠 처리: 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');
-
복사 코드
|