php--phpexcel类生成excel文档
程序员文章站
2022-04-09 21:43:44
...
<span>shi yong phpexcel sheng cheng excel wen dang</span>
<hr>
<?php
//显示所有错误警告
error_reporting(E_ALL);
//引用,注意请自行下载PHPExcel-1.8类,并按照此路径放置在工程内
require_once 'PHPExcel-1.8/Classes/PHPExcel.php';
//实例化
$obj_phpexcel = new PHPExcel();
//设置活动页索引
$obj_phpexcel->setActiveSheetIndex(0);
//合并单元格
$obj_phpexcel->getActiveSheet()->mergeCells('A1:E2');
//单元格设置格式,粗体,居中对齐,边框,颜色
$obj_phpexcel->getActiveSheet()->getStyle('A1:E2')->applyFromArray(
array(
'font'=>array('bold'=>true),
'alignment'=>array('horizontal'=>PHPExcel_Style_Alignment::HORIZONTAL_CENTER),
'borders'=>array(
'top'=> array('style'=>PHPExcel_Style_Border::BORDER_THIN),
'fill'=> array('type'=>PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR),
'rotation'=> 90,
'startcolor'=> array('rgb'=>'dcdcdc'),
'endcolor'=> array('rgb'=>'ffffff')
)
)
);
//设置字号18px
$obj_phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(18);
//填入内容
$obj_phpexcel->getActiveSheet()->setCellValue('A1','I Love PHP, Do you like it?');
//获取当前页A1格的字体,设置颜色为绿色
$obj_phpexcel->getActiveSheet()->getStyle('A1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
//设置单元格为填充,颜色
$obj_phpexcel->getActiveSheet()->getStyle('A3:E3')->applyFromArray(
array(
'fill'=> array('type'=>PHPExcel_Style_Fill::FILL_SOLID, 'color'=> array('rgb'=>'efefef')),
)
);
//设置单元格居中对齐
$obj_phpexcel->getActiveSheet()->getStyle('A3:E3')->applyFromArray(
array(
'alignment'=> array('horizontal'=>PHPExcel_Style_Alignment::HORIZONTAL_CENTER)
)
);
//填入内容
$obj_phpexcel->getActiveSheet()->setCellValue('A3','虾');
$obj_phpexcel->getActiveSheet()->setCellValue('B3','米');
$obj_phpexcel->getActiveSheet()->setCellValue('C3','大');
$obj_phpexcel->getActiveSheet()->setCellValue('D3','王');
$obj_phpexcel->getActiveSheet()->setCellValue('E3','!');
//设置单元格列为自动大小
$obj_phpexcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
//再次设定当前页索引
$obj_phpexcel->setActiveSheetIndex(0);
//生成excel2007文档,特别注意'Excel2007'中间不能有空格
$obj_writer = PHPExcel_IOFactory::createWriter($obj_phpexcel,'Excel2007');
//保存文档
$obj_writer->save('excel01.xlsx');
//生成excel5文档
$obj_writer = PHPExcel_IOFactory::createWriter($obj_phpexcel,'Excel5');
//保存文档
$obj_writer->save('excel02.xls');
?>
推荐阅读
-
Java和.Net版通用工具类实现--生成自定义Web Html/Excel测试用例和测试报告
-
excel根据rgb自动填充颜色_根据EXCEL数据自动生成WORD文档
-
JSP生成Excel报表文档源代码
-
Java利用POI生成Word、Excel文档转换成PDF,PDF转换成图片
-
Golang生成Excel文档的方法步骤
-
asp.net生成excel文件的类
-
服务器巡检shell脚本,python生成excel文档并邮件发出
-
Excel自动保存生成一个后缀名为xlk的备份文档且可直接编辑
-
TCPDF:用于生成PDF文档的开源PHP类
-
shimokita glory days PHP Smarty生成EXCEL文档的代码