.xls를 출력하여 Excel 만들기 $objPHPExcel = new PHPExcel(); Excel 저장—2007 형식 - $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel)
- /또는 $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); 2007이 아닌 형식
- $objWriter->save("xxx.xlsx");
-
-
- 코드 복사
-
-
- 2, 브라우저에 직접 출력
-
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel) header("Pragma: public"); header("만료일: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0") header("Content-Type:application/force -download"); header("Content-Type:application/vnd.ms-execl"); - header("Content-Type:application/octet-stream");
- header( "Content -Type:application/download");;
- header('Content-Disposition:attachment;filename="resume.xls"')
- header("Content-Transfer-Encoding:binary");
- $objWriter->save('php://output');
3. Excel 속성 설정:
- Creator
- $objPHPExcel->getProperties ()->setCreator("Maarten Balliauw");
- 최종 수정자
- $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw")
- 제목
- $objPHPExcel ->getProperties()->setTitle("office 2007 XLSX 테스트 문서")
- 제목
- $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX 테스트 문서")
- 설명
- $objPHPExcel->getProperties()->setDescription("PHP 클래스를 사용하여 생성된 Office 2007 XLSX용 테스트 문서.")
- 키워드
- $objPHPExcel->getProperties( ) ->setKeywords("office 2007 openxml php");
- 범주
- $objPHPExcel->getProperties()->setCategory("테스트 결과 파일");
-
-
-
- 코드 복사
-
-
4, 기타
-
- 현재 시트 설정
- $objPHPExcel->setActiveSheetIndex(0)
- 시트 이름 설정
- $objPHPExcel->getActiveSheet () ->setTitle('Simple');
- 셀 값 설정
- $objPHPExcel->getActiveSheet()->setCellValue('A1′, 'String')
- $ objPHPExcel->getActiveSheet()->setCellValue('A2′, 12);
- $objPHPExcel->getActiveSheet()->setCellValue('A3′, true); getActiveSheet() ->setCellValue('C5′, '=SUM(C2:C4)')
- $objPHPExcel->getActiveSheet()->setCellValue('B8′, '=MIN(B2:C5) )') ;
- 셀 병합
- $objPHPExcel->getActiveSheet()->mergeCells('A18:E22′)
- 셀 분리
- $objPHPExcel->getActiveSheet()-> ; unmergeCells('A28:B28′);
- 셀 보호
- $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true) // 순서대로 설정해야 합니다. 워크시트 보호를 활성화하려면
- $objPHPExcel->getActiveSheet()->protectCells('A3:E13′, 'PHPExcel')
- 형식 설정
- // 셀 번호 형식 설정
- echo date('H:i:s') . " 셀 번호 형식 설정"
- $objPHPExcel->getActiveSheet()->getStyle('E4′)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat ::FORMAT_CURRENCY_EUR_SIMPLE);
- $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4′), 'E5:E13′ )
- 설정 너비
- // 열 너비 설정
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true)
- $objPHPExcel->getActiveSheet()- >getColumnDimension('D')->setWidth(12);
- 글꼴 설정
- $objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()-> setName('Candara');
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20)
- $objPHPExcel->getActiveSheet ()->getStyle('B1′)->getFont()->setBold(true)
- $objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont( )->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
- $objPHPExcel->getActiveSheet()->getStyle('B1′)->getFont()->getColor()->setARGB(PHPExcel_Style_Color ::COLOR_WHITE);
- $objPHPExcel->getActiveSheet()->getStyle('E1′)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); >$objPHPExcel->getActiveSheet()->getStyle('D13′)->getFont()->setBold(true)
- $objPHPExcel->getActiveSheet()->getStyle('E13 ')->getFont()->setBold(true);
- 정렬 설정
- $objPHPExcel->getActiveSheet()->getStyle('D11′)->getAlignment()-> setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- $objPHPExcel->getActiveSheet()->getStyle('D12′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT)
- $obj PHPExcel ->getActiveSheet()->getStyle('D13′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT)
- $objPHPExcel->getActiveSheet()->getStyle(' A18 ′)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
- //세로 중심
- $objPHPExcel->getActiveSheet()->getStyle('A18′)-> getAlignment ()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)
- 열의 테두리 설정
- $objPHPExcel->getActiveSheet()->getStyle('A4′)->getBorders()-> ;getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
- $objPHPExcel->getActiveSheet()->getStyle('B4′)->getBorders()->getTop()-> setBorderStyle( PHPExcel_Style_Border::BORDER_THIN)
- $objPHPExcel->getActiveSheet()->getStyle('C4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN) ;
- $objPHPExcel->getActiveSheet()->getStyle('D4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
- $objPHPExcel- > getActiveSheet()->getStyle('E4′)->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
- 테두리 색상 설정
- $objPHPExcel- > getActiveSheet()->getStyle('D13')->getBorders()->getLeft()->getColor()->setARGB('FF993300')
- $objPHPExcel-> getActiveSheet( )->getStyle('D13′)->getBorders()->getTop()->getColor()->setARGB('FF993300′)
- $objPHPExcel->getActiveSheet( )- >getStyle('D13′)->getBorders()->getBottom()->getColor()->setARGB('FF993300′)
- $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getTop()->getColor()->setARGB('FF993300');
- $objPHPExcel->getActiveSheet()->getStyle('E13′)->getBorders()->getBottom()->getColor()->setARGB('FF993300′);
- $objPHPExcel->getActiveSheet()->getStyle('E13′)->getBorders()->getRight()->getColor()->setARGB('FF993300′);
- 设置填充颜color
- $objPHPExcel->getActiveSheet()->getStyle('A1′)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objPHPExcel->getActiveSheet()->getStyle('A1′)->getFill()->getStartColor()->setARGB('FF808080′);
- $objPHPExcel->getActiveSheet()->getStyle('B1′)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
- $objPHPExcel->getActiveSheet()->getStyle('B1′)->getFill()->getStartColor()->setARGB('FF808080′);
- 그림 //bbs.it-home.org
- $obj드로잉 = new PHPExcel_Worksheet_드로잉();
- $obj드로잉->setName('로고');
- $obj드로잉->setDescription('로고');
- $obj드로잉->setPath('./images/officelogo.jpg');
- $obj드로잉->setHeight(36);
- $obj드로잉->setWorksheet($objPHPExcel->getActiveSheet());
- $obj드로잉 = 새로운 PHPExcel_Worksheet_드로잉();
- $obj드로잉->setName('유료');
- $obj드로잉->setDescription('유료');
- $obj드로잉->setPath('./images/paid.png');
- $obj드로잉->setCoordinates('B15′);
- $obj드로잉->setOffsetX(110);
- $obj드로잉->setRotation(25);
- $obj드로잉->getShadow()->setVisible(true);
- $obj드로잉->getShadow()->setDirection(45);
- $obj드로잉->setWorksheet($objPHPExcel->getActiveSheet());
- 현재 默认sheet后,创建一个worksheet
- echo date('H:i:s') . " 새 워크시트 개체 만들기";
- $objPHPExcel->createSheet();
- $objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
- $objWriter-save('php://output');
复代码
|