PHPEXCEL은 매우 강력한 MS Office Excel 문서 세대 클래스 라이브러리입니다. 비교적 복잡한 형식 데이터를 출력 해야하는 경우 PHPEXCEL이 좋은 선택입니다. 그러나 사용량은 비교적 복잡합니다. 녹음하려면 나열하십시오.
코드 사본은 다음과 같습니다.
<?
// phpexcel 클래스 라이브러리의 포함 경로를 설정합니다
set_include_path ( '.'. path_separator.
'D :/Zeal/Php_Libs'. path_separator.
get_include_path ());
/**
* 다음은 사용의 예입니다. ////로 시작하는 라인의 경우 다른 선택적 방법이 있습니다. 실제 요구에 따라 사용하십시오.
* 해당 라인에서 주석을 엽니 다.
* Excel5를 사용하는 경우 출력은 GBK 인코딩되어야합니다.
*/
require_once 'phpexcel.php';
// 탁자
//// require_once 'phpexcel/writer/excel5.php'; // 다른 하위 버전의 XL에 사용됩니다
// 또는
//// require_once 'phpexcel/writer/excel2007.php'; // Excel-2007 형식
// 처리 객체 인스턴스를 만듭니다
$ objexcel = 새로운 phpexcel ();
// 파일 형식을 작성하여 객체 인스턴스를 쓰지 않습니다
//// $ objwriter = new phpexcel_writer_excel5 ($ objexcel); // 다른 버전 형식에 사용됩니다
// 또는
//// $ objwriter = new phpexcel_writer_excel2007 ($ objexcel); // 2007 년 형식
// $ objwriter-> setOffice2003compatibility (true);
// *************************************************************
// 기본 문서 속성을 설정합니다
$ objprops = $ objexcel-> getProperties ();
$ objprops-> setCreator ( "Zeal Li");
$ objprops-> setLastModifiedBy ( "Zeal Li");
$ objprops-> settitle ( "Office XLS 테스트 문서");
$ objprops-> setSubject ( "Office XLS 테스트 문서, 데모");
$ objprops-> setDescription ( "phpexcel에 의해 생성 된 테스트 문서");
$ objprops-> setkeywords ( "Office Excel Phpexcel");
$ objprops-> setCategory ( "테스트");
// *************************************************************
// 후속 컨텐츠 작업의 현재 시트 인덱스를 설정합니다.
// 일반적으로 호출은 여러 시트를 사용하는 경우에만 호출이 필요합니다.
// 기본적으로 phpexcel은 자동으로 첫 번째 시트를 생성하고 sheetIndex = 0을 설정합니다.
$ objexcel-> setActiveSheetIndex (0);
$ objactsheet = $ objexcel-> getActiveSheet ();
// 현재 활성 시트의 이름을 설정합니다
$ objactsheet-> settitle ( '테스트 시트');
// *************************************************************
// 셀 내용을 설정합니다
//
// phpexcel 수신 내용에 따라 셀 내용 유형을 자동으로 결정합니다.
$ objactsheet-> setCellValue ( 'A1', 'String Content'); // 문자열 내용
$ objactsheet-> setCellValue ( 'a2', 26); // 값
$ objactsheet-> setCellValue ( 'a3', true); // 부울 가치
$ objactsheet-> setCellValue ( 'a4', '= sum (a2 : a2)'); // 공식
// 설명 컨텐츠 유형을 지정합니다
$ objactsheet-> setCellValueExplicit ( 'a5', '847475847857487584',
phpexcel_cell_datatype :: type_string);
// 셀을 병합합니다
$ objactsheet-> mergecells ( 'b1 : c22');
// 별도의 셀
$ objactsheet-> unmergecells ( 'b1 : c22');
// *************************************************************
// 셀 스타일을 설정합니다
//
// 너비를 설정합니다
$ objactsheet-> getColumnDimension ( 'b')-> setAutosize (true);
$ objactsheet-> getColumnDimension ( 'a')-> setWidth (30);
$ objstylea5 = $ objactsheet-> getstyle ( 'a5');
// 셀 내용의 숫자 형식을 설정합니다.
//
// phpexcel_writer_excel5가 컨텐츠를 생성하는 데 사용되는 경우
// 여기에서 phpexcel_style_numberformat class에 정의 된 const 변수
// 다양한 사용자 정의 형식 중에서 다른 유형을 정상적으로 사용할 수 있지만 setFormatCode시면
// format_number 일 때 실제 효과는 "0"으로 설정되지 않습니다. 필요
// phpexcel_writer_excel5_format class의 소스 코드에서 getxf ($ style) 메소드를 수정합니다.
// 이전 if ($ this-> _ biff_version == 0x0500) {(줄 363)
// 라인 코드 :
// if ($ ifmt === '0') $ ifmt = 1;
//
// 많은 숫자를 피하기 위해 형식을 phpexcel_style_numberformat :: format_number로 설정합니다.
// 과학 계산 방법을 사용하여 표시됩니다. 다음 setAutosize 방법과 함께 각 라인의 내용을 만들 수 있습니다.
// 모두 원본 내용에 따라 표시됩니다.
$ objstylea5
-> getNumberformat ()
-> setFormatCode (phpexcel_style_numberformat :: format_number);
// 글꼴을 설정합니다
$ objfonta5 = $ objstylea5-> getfont ();
$ objfonta5-> setName ( 'Courier New');
$ objfonta5-> setSize (10);
$ objfonta5-> setBold (true);
$ objfonta5-> setunderline (phpexcel_style_font :: 밑줄 _single);
$ objfonta5-> getColor ()-> setArgb ( 'ff9999999');
// 정렬을 설정합니다
$ objaligna5 = $ objstylea5-> getAlignment ();
$ objaligna5-> Sethorizontal (phpexcel_style_alignment :: horizontal_right);
$ objaligna5-> setvertical (phpexcel_style_alignment :: vertical_center);
// 테두리를 설정합니다
$ objbordera5 = $ objstylea5-> getBorders ();
$ objbordera5-> getTop ()-> setBordersTyle (phpexcel_style_border :: border_thin);
$ objbordera5-> getTop ()-> getColor ()-> setArgb ( 'ffff0000'); // 색상
$ objbordera5-> getBottom ()-> setBordersTyle (phpexcel_style_border :: border_thin);
$ objbordera5-> getleft ()-> setborderstyle (phpexcel_style_border :: border_thin);
$ objbordera5-> getright ()-> setborderstyle (phpexcel_style_border :: border_thin);
// 채우기 색상을 설정합니다
$ objfilla5 = $ objstylea5-> getFill ();
$ objfilla5-> setfillType (phpexcel_style_fill :: fill_solid);
$ objfilla5-> getStartColor ()-> setArgb ( 'ffeeeee');
// 지정된 셀에서 스타일 정보를 복사합니다.
$ objactsheet-> duplicatestyle ($ objstylea5, 'b1 : c22');
// *************************************************************
// 사진 추가
$ objdrawing = 새로운 phpexcel_worksheet_drawing ();
$ objdrawing-> setName ( 'Zealimg');
$ objdrawing-> setDescription ( 'Zeal에 의해 삽입 된 이미지');
$ objdrawing-> setPath ( './ Zeali.net.logo.gif');
$ objdrawing-> setheight (36);
$ objdrawing-> setCoordinates ( 'C23');
$ objdrawing-> setOffsetx (10);
$ objdrawing-> setRotation (15);
$ objdrawing-> getShadow ()-> setvisible (true);
$ objdrawing-> getShadow ()-> setDirection (36);
$ objdrawing-> setworksheet ($ objactsheet);
// 새 워크 시트를 추가합니다
$ objexcel-> createSheet ();
$ objexcel-> getsheet (1)-> settitle ( 'test 2');
// 셀을 보호합니다
$ objexcel-> getsheet (1)-> getProtection ()-> setsheet (true);
$ objexcel-> getsheet (1)-> ProtectCells ( 'a1 : c22', 'phpexcel');
// *************************************************************
// 컨텐츠 출력
//
$ outputfilename = "output.xls";
// 파일에
//// $ objwriter-> 저장 ($ outputfilename);
//또는
// 브라우저에
/// Header ( "Content-Type : Application/Force-Download");
/// header ( "Content-Type : Application/Octet-stream");
/// Header ( "Content-Type : Application/Download");
/// Header('Content-Disposition:inline ;filename="'.$itputfilename. ' ");
/// header ( "Content-Transfer-Encoding : Binary");
/// HEADER ( "만료 : MON, 26 JUL 1997 05:00:00 GMT");
/// HEADER ( "최종 수정 :". gmdate ( "d, d myh : i : s"). "gmt");
/// HEADER ( "캐시-제어 : Must-Revalidate, Post-Check = 0, pre-Check = 0");
/// Header ( "Pragma : No-Cache");
//// $ objwriter-> 저장 ( 'php : // output');
?>