PhpExcel笔记,phpExcel中文帮助手册



引用PHPExcel

 'PHPExcel.php' 'PHPExcel/Writer/Excel2007.php' =  PHPExcel();

设置excel的属性

//创建人

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");

//最后修改人

$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");

//标题

$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");

//题目

$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");

//描述

$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");

//关键字

$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");

//种类

$objPHPExcel->getProperties()->setCategory("Test result file");

也可用下面这种方式

$objPHPExcel->getProperties()->setCreator("ctos")  

            ->setLastModifiedBy("ctos")  

            ->setTitle("Office 2007 XLSX Test Document")  

            ->setSubject("Office 2007 XLSX Test Document")  

            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")  

            ->setKeywords("office 2007 openxml php")  

            ->setCategory("Test result file");




设置当前的sheet

$objPHPExcel->setActiveSheetIndex(0);

设置sheet的标题

$objPHPExcel->getActiveSheet()->setTitle('Simple');

设置单元格宽度

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);

设置单元格高度

$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(40);

合并单元格

$objPHPExcel->getActiveSheet()->mergeCells('A18:E22');

拆分单元格

$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');

设置保护cell,保护工作表

$objPHPExcel->getActiveSheet()->getProtection()->setSheet(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' );

设置加粗

$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);

设置水平对齐方式(HORIZONTAL_RIGHT,HORIZONTAL_LEFT,HORIZONTAL_CENTER,HORIZONTAL_JUSTIFY)

$objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

设置垂直居中

$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

设置字号

$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);

设置边框

$objPHPExcel->getActiveSheet()->getStyle('A1:I20')->getBorders()->getAllBorders()->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');



评论



分享

最新加入

最新评论

bestphper: 就是就是 查看原文 01月12日 14:32
╰ゝ牵手丶永恒: 不错学习一下,只有不断的共享祖国才会更强大!哈哈 查看原文 01月08日 17:06





作者:Stubborn 京ICP备18062026号-1