-
-
//写入excel文件 - //클래스 포함
- require_once('클래스/ PHPExcel.php');
- require_once('Classes/PHPExcel/Writer/Excel2007.php');
- $objPHPExcel = new PHPExcel();
//Set 속성 设置文件属性
- $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("테스트 결과 파일");
//데이터 추가 添加数据
- $ objPHPExcel->setActiveSheetIndex(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello');//可以指정位置
- $objPHPExcel->getActiveSheet() ->setCellValue('A2', true);
- $objPHPExcel->getActiveSheet()->setCellValue('A3', false);
- $objPHPExcel->getActiveSheet()->setCellValue ('B2', '세계!');
- $objPHPExcel->getActiveSheet()->setCellValue('B3', 2);
- $objPHPExcel->getActiveSheet()->setCellValue( 'C1', 'Hello');
- $objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!');
//循环
- for($i = 1;$i<200;$i ) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, '테스트 값');
- }
//日期格式化
- $objPHPExcel->getActiveSheet()->setCellValue('D1', time());
- $objPHPExcel-> getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
//댓글 추가 添加注释
- $objPHPExcel->getActiveSheet()->getComment('E11')->setAuthor('PHPExcel');
- $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E11') ->getText()->createTextRun('PHPExcel:');
- $objCommentRichText->getFont()->setBold(true);
- $objPHPExcel->getActiveSheet()-> getComment('E11')->getText()->createTextRun("rn");
- $objPHPExcel->getActiveSheet()->getComment('E11')->getText()-> ;createTextRun('VAT를 제외한 현재 청구서의 총액.');
//서식 있는 텍스트 문자열 추가 添加文字 可设置样式
- $objRichText = new PHPExcel_RichText( $objPHPExcel->getActiveSheet()->getCell('A18') );
- $objRichText->createText('이 송장은 ');
- $objPayable = $objRichText->createTextRun(' 월말 이후 30일 이내에 지급');
- $objPayable->getFont()->setBold(true);
- $objPayable->getFont()->setItalic(true) ;
- $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
- $objRichText->createText(', 송장에 달리 지정되지 않는 한.');< ;/p>
//셀 병합 合并分离单元格
- $objPHPExcel->getActiveSheet()->mergeCells('A18:E22');
- $objPHPExcel-> getActiveSheet()->unmergeCells('A18:E22');
//셀 보호 保护单元格
- $objPHPExcel->getActiveSheet()->getProtection( )->setSheet(true);//워크시트 보호를 활성화하려면 true로 설정해야 합니다!
- $objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel' );
//셀 번호 형식 설정 数字格式化
- $objPHPExcel->getActiveSheet()->getStyle('E4')->getNumberFormat()- >setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
- $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4'), 'E5:E13' ) ;
//열 너비 설정 设置列宽titude
- $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('D11')->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('A3')->getAlignment()->setWrapText(true);
-
//열 테두리 설정 设置列边框
- $objPHPExcel->getActiveSheet()->getStyle('A4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border ::BORDER_THIN);
- $objPHPExcel->getActiveSheet()->getStyle('A10')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- $objPHPExcel->getActiveSheet()->getStyle('E10')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- $objPHPExcel->getActiveSheet ()->getStyle('D13')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- $objPHPExcel->getActiveSheet()->getStyle('E13')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- < p>//테두리 색상 설정 设置边框颜color
- $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()->getRight()->getColor()->setARGB('FF993300' );
//채우기 설정 设置填充
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType (PHPExcel_Style_Fill::FILL_SOLID);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('FF808080');< ;/p>
//시트에 하이퍼링크 추가 添加链接
- $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net');
- $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net');
- $objPHPExcel- >getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('웹사이트로 이동');
- $objPHPExcel->getActiveSheet()->getStyle('E26 ')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
//워크시트에 그림 추가 添加图文
- $obj드로잉 = new PHPExcel_Worksheet_드로잉( );
- $obj드로잉->setName('로고');
- $obj드로잉->setDescription('로고');
- $obj드로잉->setPath('./images/officelogo.jpg ');
- $obj드로잉->setHeight(36);
- $obj드로잉->setCoordinates('B15');
- $obj드로잉->setOffsetX(110);
- $obj드로잉- >setRotation(25);
- $obj드로잉->getShadow()->setVisible(true);
- $obj드로잉->getShadow()->setDirection(45);
- $obj드로잉 ->setWorksheet($objPHPExcel->getActiveSheet());
//행과 열을 삽입하고 제거해 보세요
- $objPHPExcel->getActiveSheet()- >insertNewRowBefore(6, 10);
- $objPHPExcel->getActiveSheet()->removeRow(6, 10);
- $objPHPExcel->getActiveSheet()->insertNewColumnBefore('E', 5);
- $objPHPExcel->getActiveSheet()->removeColumn('E', 5);
//조건부 서식 추가
- $objConditional1 = new PHPExcel_Style_Conditional();
- $objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS);
- $objConditional1->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN);
- $objConditional1->setCondition('0' ) ;
- $objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
- $objConditional1->getStyle()->getFont ()->setBold(true);
//자동 필터 설정 自动过滤
- $objPHPExcel->getActiveSheet()->setAutoFilter('A1:C9') ;
//"전화" 및 "팩스" 열 숨기기 隐藏列
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible (false);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false);
//문서 보안 설정 设置文档안전
- $objPHPExcel->getSecurity()->setLockWindows(true);
- $objPHPExcel->getSecurity()->setLockStructure(true);
- $objPHPExcel->getSecurity( )->setWorkbookPassword("PHPExcel");
//시트 보안 설정 设置工작업表안전
- $objPHPExcel->getActiveSheet()->getProtection()- >setPassword('PHPExcel');
- $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);// 다음 중 하나를 활성화하려면 이 기능을 활성화해야 합니다!
- $objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
- $objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
- $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
//계산된 데이터 计算
- echo 'B14 값 [ =횟수(B2:B12)]: ' . $objPHPExcel->getActiveSheet()->getCell('B14')->getCalculatedValue() . "rn";
//개요 수준 설정
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1);
- $objPHPExcel->getActiveSheet()-> ;getColumnDimension('E')->setVisible(false);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setCollapsed(true);
//창 고정
- $objPHPExcel->getActiveSheet()->freezePane('A2');
//상단에서 반복할 행
- $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1);
//데이터 유효성 검사 설정 验证输入值
- $ objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation();
- $objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE );
- $objValidation-> setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
- $objValidation->setAllowBlank(true);
- $objValidation->setShowInputMessage(true);
- $objValidation->setShowErrorMessage(true);
- $objValidation->setErrorTitle('입력 오류');
- $objValidation->setError('번호가 허용되지 않습니다!');
- $objValidation->setPromptTitle('허용된 입력');
- $objValidation->setPrompt('10에서 20 사이의 숫자만 허용됩니다.');
- $objValidation->setFormula1(10);
- $objValidation->setFormula2(20);
- $objPHPExcel->getActiveSheet()->getCell('B3')->setDataValidation($objValidation);
//기본 시트 뒤에 새 워크시트를 만듭니다. 创建새로운 작업
- $objPHPExcel->createSheet();
- $objPHPExcel->setActiveSheetIndex(1);
//머리글과 바닥글을 설정합니다. 홀수/짝수에 대해 다른 헤더가 사용되지 않는 경우 홀수 헤더가 가정됩니다. 页眉页脚
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&H이 문서를 기밀로 처리해 주십시오!');
- $objPHPExcel->getActiveSheet()-> ;getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');
// 페이지 방향 및 크기 설정 方向大小
- $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
- $objPHPExcel->getActiveSheet()->getPageSetup ()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
//시트 이름 바꾸기 큼직한 작업 'Simple');
//활성 시트 인덱스를 첫 번째 시트로 설정하여 Excel에서 이를 첫 번째 시트로 엽니다
- $objPHPExcel->setActiveSheetIndex(0);< ;/p>
//Excel 2007 파일 저장 保存
- $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
- $objWriter->save(str_replace('.php', '. xlsx', __FILE__));
-
- //Excel 5 파일 저장 保存
- require_once('Classes/PHPExcel/Writer/Excel5.php');
- $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel) ;
- $objWriter->save(str_replace('.php', '.xls', __FILE__));
//1.6.2신규版保存
- require_once ('Classes/PHPExcel/IOFactory.php');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save(str_replace('.php', '. xls', __FILE__));
- 读excel
//클래스 포함
- require_once('Classes/PHPExcel/Reader/Excel2007.php');
- $objReader = new PHPExcel_Reader_Excel2007;
- $objPHPExcel = $objReader->load("05featuredemo.xlsx");
- 读写csv
require_once("05featuredemo.inc.php" );
- require_once('Classes/PHPExcel/Writer/CSV.php');
- require_once('Classes/PHPExcel/Reader/CSV.php');
- require_once('Classes/PHPExcel/Writer/ Excel2007.php');
- //CSV 형식으로 쓰기 写
- $objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
- $objWriter->setDelimiter(';');
- $objWriter- >setEnclosure('');
- $objWriter->setLineEnding("rn");
- $objWriter->setSheetIndex(0);
- $objWriter->save(str_replace('. php', '.csv', __FILE__));
- //CSV 형식에서 읽기 读
- $objReader = new PHPExcel_Reader_CSV();
- $objReader->setDelimiter(';');
- $objReader->setEnclosure('');
- $objReader->setLineEnding("rn");
- $objReader->setSheetIndex(0);
- $objPHPExcelFromCSV = $objReader-> ;load(str_replace('.php', '.csv', __FILE__));
- //Excel2007 형식으로 쓰기
- $objWriter2007 = new PHPExcel_Writer_Excel2007($objPHPExcelFromCSV);
- $objWriter2007->save (str_replace('.php', '.xlsx', __FILE__));
- 写html
require_once("05featuredemo.inc.php");
- require_once('Classes/PHPExcel/Writer/HTML.php');
- //HTML 형식으로 쓰기
- $objWriter = new PHPExcel_Writer_HTML ($objPHPExcel);
- $objWriter->setSheetIndex(0);
- $objWriter->save(str_replace('.php', '.htm', __FILE__));
- 写pdf< /p>
require_once("05featuredemo.inc.php");
- require_once('Classes/PHPExcel/IOFactory.php');
- //PDF 형식으로 쓰기
- $ objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
- $objWriter->setSheetIndex(0);
- $objWriter->save(str_replace('.php', '.pdf', __FILE__));
- //에코 메모리 최대 사용량
- echo date('H:i:s') . " 최대 메모리 사용량: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MBrn";
-
复代码
|