当前位置:首页 > PHP > 关键词 > 表格 > 正文

PhpOffice属性设置详解

PhpOffice属性设置详解(PHP导出excel属性参数设置大全)

一、Excel基本信息

1、创建人
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");

2、最后修改人
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");

3、标题
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");

4、题目
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");

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

6、关键字
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");

7、种类
$objPHPExcel->getProperties()->setCategory("Test result file");

二、单元格设置

1、设置当前的sheet
$objPHPExcel->setActiveSheetIndex(0);

2、设置sheet的name
$objPHPExcel->getActiveSheet()->setTitle('Simple');

3、设置单元格的值
$objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C5)');

4、合并单元格
$objPHPExcel->getActiveSheet()->mergeCells('A18:E22');

5、分离单元格
$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');
 
6、保护cell
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); 
$objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');

7、设置格式
$objPHPExcel->getActiveSheet()->getStyle('E4')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('E4'), 'E5:E13' );

8、设置宽单元格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);

9、设置单元格字体
$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('E13')->getFont()->setBold(true);

10、设置align
$objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
垂直居中
$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
11、设置单元的边框
$objPHPExcel->getActiveSheet()->getStyle('A4')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

12、设置边框的颜色
$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');

13、设置填充颜色
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setARGB('FF808080');

三、插入图片

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Paid');
$objDrawing->setDescription('Paid');
$objDrawing->setPath('./images/paid.png');
$objDrawing->setCoordinates('B15');
$objDrawing->setOffsetX(110);
$objDrawing->setRotation(25);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
 


本文属原创,转载请注明原文:https://www.zhimatong.com/jiaocheng/945.html

为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。

内容有用

联系
顾问

在线
客服
账号登录

没有账号?立即注册

忘记密码

登录即同意用户协议没有账号? 立即注册
账号注册
我已阅读并同意用户协议
立即注册
注册即同意用户协议已有账号? 立即登录
找回密码

操作步骤:邮箱验证->设置新密码

注册即同意用户协议已有账号? 立即登录