> php教程 > PHP源码 > PHP导出Excel的类库,支持附带图片

PHP导出Excel的类库,支持附带图片

PHP中文网
풀어 주다: 2016-05-25 17:13:06
원래의
1108명이 탐색했습니다.

PHP导出Excel的类库,支持附带图片         

<?php
require_once &#39;./Classes/PHPExcel.php&#39;;
require_once &#39;./Classes/PHPExcel/IOFactory.php&#39;;
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                             ->setLastModifiedBy("Maarten Balliauw")
                             ->setTitle("Office 2007 XLSX Test Document")
                             ->setSubject("Office 2007 XLSX Test Document")
                             ->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")
                             ->setKeywords("office 2007 openxml php")
                             ->setCategory("Test result file");
                              
$objPHPExcel->setActiveSheetIndex(0);
$objRichText = new PHPExcel_RichText();
$objRichText->createText(&#39;&#39;);
$objPayable = $objRichText->createTextRun(&#39;PHP导出的Excel&#39;);
$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_RED ));
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setSize(24);
$objPHPExcel->getActiveSheet()->getCell(&#39;B1&#39;)->setValue($objRichText);
$objPHPExcel->getActiveSheet()->getStyle(&#39;B1&#39;)->getFont()->setBold(true);       // 加粗
$objPHPExcel->getActiveSheet()->getStyle(&#39;B1&#39;)->getFont()->setSize(24);         // 字体大小
$objPHPExcel->getActiveSheet()->getStyle(&#39;B1&#39;)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED); // 文本颜色
$objPHPExcel->getActiveSheet()->getStyle(&#39;A1:G1&#39;)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle(&#39;A1:G1&#39;)->getFill()->getStartColor()->setARGB(&#39;00FFFFE3&#39;);          // 底纹
 
// 列宽
//$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;A&#39;)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;A&#39;)->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;B&#39;)->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;C&#39;)->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;D&#39;)->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;E&#39;)->setWidth(12);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;F&#39;)->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension(&#39;G&#39;)->setWidth(20);
 
// 行高
for($i = 2; $i <= 17; $i++)
{
    $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(22);
}
 
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A2&#39;, &#39;姓名&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A3&#39;, &#39;PHP&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A4&#39;, &#39;EXCEL&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A5&#39;, &#39;&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A6&#39;, &#39;XXX&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A7&#39;, &#39;V&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A8&#39;, &#39;d&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A9&#39;, &#39;name&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A10&#39;, &#39;描述&#39;);
for($i = 2; $i <= 16; $i++)
{
    $objPHPExcel->getActiveSheet()->getStyle(&#39;A&#39; . $i)->getFont()->setBold(true);       // 加粗
}
 
$objPHPExcel->getActiveSheet()->setCellValue(&#39;B2&#39;, &#39;[姓名]&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;B3&#39;, &#39;导出带图片的EXCEL&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;B4&#39;, &#39;XXXXX&#39;);
 
// 为excel加图片
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName(&#39;Photo&#39;);
$objDrawing->setDescription(&#39;Photo&#39;);
$objDrawing->setPath(&#39;./images/PIC.jpg&#39;);
$objDrawing->setHeight(170);
$objDrawing->setWidth(120);
$objDrawing->setCoordinates(&#39;G2&#39;);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
 
$objPHPExcel->getActiveSheet()->setCellValue(&#39;A17&#39;, &#39;其它要求&#39;);
$objPHPExcel->getActiveSheet()->setCellValue(&#39;B17&#39;, &#39;[其它要求]&#39;);
 
$objPHPExcel->getActiveSheet()->getStyle(&#39;A17&#39;)->getFont()->setBold(true);      // 加粗
 
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle(&#39;Excel表&#39;);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, &#39;Excel5&#39;);
$objWriter->save(&#39;PHP导出Excel.xls&#39;);
로그인 후 복사

         

2. [文件] PHPExcel.rar

PHP导出Excel的类库,支持附带图片PHPExcel.rar


       

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿