Excel基本函数说明
Posted 蓝庭英
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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());
以上是关于Excel基本函数说明的主要内容,如果未能解决你的问题,请参考以下文章