phpExcel中文帮助手册
phpExcel中文帮助手册
Admin
2011年11月13日
名人名言:上人生的旅途吧。前途很远,也很暗。然而不要怕。不怕的人的面前才有路。——有岛武郎
下面是总结的几个应用办法
include ""PHPExcel.php"";
include ""PHPExcel/Writer/Excel2007.php"";
//或者include ""PHPExcel/Writer/Excel5.php""; 用于输出.xls的
创建一个excel
¥objPHPExcel = new PHPExcel();
保存excel—2007格局
¥objWriter = new PHPExcel_Writer_Excel2007(¥objPHPExcel);
//或者¥objWriter = new PHPExcel_Writer_Excel5(¥objPHPExcel); 非2007格局
¥objWriter->save("xxx.xlsx");
直接输出到浏览器
¥objWriter = new PHPExcel_Writer_Excel5(¥objPHPExcel);
header("Pragma: public");
header("Expires: 0″);
header("Cache-Control:must-revalidate, post-check=0, pre-check=0″);
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header(""Content-Disposition:attachment;filename="resume.xls""");
header("Content-Transfer-Encoding:binary");
¥objWriter->save(""php://output"");
——————————————————————————————————————–
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");
——————————————————————————————————————–
设置当前的sheet
¥objPHPExcel->setActiveSheetIndex(0);
设置sheet的name
¥objPHPExcel->getActiveSheet()->setTitle(""Simple"");
设置单位格的值
¥objPHPExcel->getActiveSheet()->setCellValue(""A1"", ""String"");
¥objPHPExcel->getActiveSheet()->setCellValue(""A2"", 12);
¥objPHPExcel->getActiveSheet()->setCellValue(""A3"", true);
¥objPHPExcel->getActiveSheet()->setCellValue(""C5"", ""=SUM(C2:C4)"");
¥objPHPExcel->getActiveSheet()->setCellValue(""B8"", ""=MIN(B2:C5)"");
归并单位格
¥objPHPExcel->getActiveSheet()->mergeCells(""A18:E22"");
分别单位格
¥objPHPExcel->getActiveSheet()->unmergeCells(""A28:B28"");
保护cell
¥objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
// Needs to be set to true in order to enable any worksheet protection!
¥objPHPExcel->getActiveSheet()->protectCells(""A3:E13"", ""PHPExcel"");
设置格局
// Set cell number formats
echo date(""H:i:s"") . " Set cell number formats\n";
¥objPHPExcel->getActiveSheet()->getStyle(""E4"")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
¥objPHPExcel->getActiveSheet()->duplicateStyle( ¥objPHPExcel->getActiveSheet()->getStyle(""E4""), ""E5:E13"" );
设置宽width
// Set column widths
¥objPHPExcel->getActiveSheet()->getColumnDimension(""B"")->setAutoSize(true);
¥objPHPExcel->getActiveSheet()->getColumnDimension(""D"")->setWidth(12);
设置font
¥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(""E1"")->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
¥objPHPExcel->getActiveSheet()->getStyle(""D13"")->getFont()->setBold(true);
¥objPHPExcel->getActiveSheet()->getStyle(""E13"")->getFont()->setBold(true);
设置align
¥objPHPExcel->getActiveSheet()->getStyle(""D11"")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
¥objPHPExcel->getActiveSheet()->getStyle(""D12"")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
¥objPHPExcel->getActiveSheet()->getStyle(""D13"")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
¥objPHPExcel->getActiveSheet()->getStyle(""A18"")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
//垂直居中
¥objPHPExcel->getActiveSheet()->getStyle(""A18"")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
设置column的border
¥objPHPExcel->getActiveSheet()->getStyle(""A4"")->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
¥objPHPExcel->getActiveSheet()->getStyle(""B4"")->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
¥objPHPExcel->getActiveSheet()->getStyle(""C4"")->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
¥objPHPExcel->getActiveSheet()->getStyle(""D4"")->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
¥objPHPExcel->getActiveSheet()->getStyle(""E4"")->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
设置border的color
¥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"");
设置填充色彩
¥objPHPExcel->getActiveSheet()->getStyle(""A1"")->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
¥objPHPExcel->getActiveSheet()->getStyle(""A1"")->getFill()->getStartColor()->setARGB(""FF808080"");
¥objPHPExcel->getActiveSheet()->getStyle(""B1"")->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
¥objPHPExcel->getActiveSheet()->getStyle(""B1"")->getFill()->getStartColor()->setARGB(""FF808080"");
加图片
¥objDrawing = new PHPExcel_Worksheet_Drawing();
¥objDrawing->setName(""Logo"");
¥objDrawing->setDescription(""Logo"");
¥objDrawing->setPath(""./images/officelogo.jpg"");
¥objDrawing->setHeight(36);
¥objDrawing->setWorksheet(¥objPHPExcel->getActiveSheet());
¥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());
//处理惩罚中文输出题目
须要将字符串转化为UTF-8编码,才干正常输出,不然中文字符将输出为空白,如下处理惩罚:
¥str = iconv(""gb2312"", ""utf-8"", ¥str);
或者你可以写一个函数专门处理惩罚中文字符串:
function convertUTF8(¥str)
{
if(empty(¥str)) return """";
return iconv(""gb2312"", ""utf-8"", ¥str);
}
//从数据库输出数据处理惩罚体式格式
从数据库读取数据如:
¥db = new Mysql(¥dbconfig);
¥sql = "SELECT * FROM 表名";
¥row = ¥db->GetAll(¥sql); // ¥row 为二维数组
¥count = count(¥row);
for (¥i = 2; ¥i <= ¥count+1; ¥i++) {
¥objPHPExcel->getActiveSheet()->setCellValue(""A"" . ¥i, convertUTF8(¥row[¥i-2][1]));
¥objPHPExcel->getActiveSheet()->setCellValue(""B"" . ¥i, convertUTF8(¥row[¥i-2][2]));
¥objPHPExcel->getActiveSheet()->setCellValue(""C"" . ¥i, convertUTF8(¥row[¥i-2][3]));
¥objPHPExcel->getActiveSheet()->setCellValue(""D"" . ¥i, convertUTF8(¥row[¥i-2][4]));
¥objPHPExcel->getActiveSheet()->setCellValue(""E"" . ¥i, convertUTF8(date("Y-m-d", ¥row[¥i-2][5])));
¥objPHPExcel->getActiveSheet()->setCellValue(""F"" . ¥i, convertUTF8(¥row[¥i-2][6]));
¥objPHPExcel->getActiveSheet()->setCellValue(""G"" . ¥i, convertUTF8(¥row[¥i-2][7]));
¥objPHPExcel->getActiveSheet()->setCellValue(""H"" . ¥i, convertUTF8(¥row[¥i-2][8]));
}
在默认sheet后,创建一个worksheet
echo date(""H:i:s"") . " Create new Worksheet object\n";
¥objPHPExcel->createSheet();
¥objWriter = PHPExcel_IOFactory::createWriter(¥objExcel, ""Excel5"");
¥objWriter-save(""php://output"");
phpExcel中文帮助手册的更多相关文章
- PhpExcel中文帮助手册|PhpExcel使用方法
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- PhpExcel笔记,phpExcel中文帮助手册
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- PhpExcel中文帮助手册|PhpExcel使用方法 ( 后面有部分没有显示出来 可以编辑中看到!!)
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- PHPExcel 中文使用手册详解
/** * * execl数据导出 * 应用场景:订单导出 * @param string $title 模型名(如Member),用于导出生成文件名的前缀 * @param array $cellN ...
- PHPExcel中文开发手册翻译版(2)
2016年8月18日12:45:14 请注意这个是粗翻译版,仅供参考,不是精校版 精校版后面才会更新 PHPExcel开发者文档 1.目录 2. 4先决条件 2.1.软件要求4 2.2.安装说明4 2 ...
- PHPExcel中文开发手册翻译版(1)
请注意这个是粗翻译版,仅供参考,不是精校版 精校版后面才会更新 英文原版在线文档 https://github.com/PHPOffice/PHPExcel/wiki/User%20Documenta ...
- PHPExcel 中文使用手册参数详解 三
设置excel的属性:创建人$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");最后修改人$ob ...
- PHPExcel 中文使用手册详解 二
$objPHPExcel = new \PHPExcel(); //定义配置 $topNumber = 2;//表头有几行占用 $xlsTitle = iconv('utf-8', 'gb2312', ...
- CentOS7 安装中文帮助手册
1.首先确定系统安装中文字体否 locale 2.rpm安装中文帮助手册 挂在光盘 将man-pages-zh-CN-1.5.2-4.el7.noarch.rpm拷贝到本机 rpm -ivh man- ...
随机推荐
- 自动化工具-jenkins
jenkins自动化工具使用教程 自动化构建.测试.部署.代码检测越来越重要.主要有一下几点原因 企业做大,项目变多,多端支持(web,h5,小程序等) 微服务提倡高内聚低耦合,项目因拆分变多 Dev ...
- @Transactional + FetchType.LYZY (hibernate) <---> Exception: could not initialize proxy - no Session;
转自: https://blog.csdn.net/blueheart20/article/details/52912023 4.问题的解决 尝试1: 在Service方法中新增了@Transact ...
- KindEditor 上传文件 在Asp.net中的使用
以前一直用FCK编辑器,因为配置比较简单,但是发现Kindeditor这个编辑器更加好看,更加灵活,就用了下. 但是发现在上传文件的时候,出现了大问题,弄了我好久的时间,为了记录下,或许能帮助到您,共 ...
- 设置Linux系统的空闲等待时间TMOUT
为了增强Linux系统的安全性,我们需要在用户输入空闲一段时间后自动断开,这个操作可以由设置TMOUT值来实现.将以下字段加入到/etc/profile 中即可(对所有用户生效). export TM ...
- echarts 知识点
echarts map 禁止放大缩小,设置 calculable 为 false 即可. calculable: false echarts 报错: There is a chart instance ...
- [转]csharp:Microsoft.Ink 手写识别(HandWriting Recognition)
原贴:http://www.cnblogs.com/geovindu/p/3702427.html 下載: //Microsoft Windows XP Tablet PC Edition 2005 ...
- 利用springMVC包装类上传多个文件
前端JSP页面代码片段: <!-- springMVC包装类上传文件 --><form name="uploadFiles" id="uploadFil ...
- 在C#客户端用HTTP上传文件到Java服务器
在C#客户端用HTTP上传文件到Java服务器 来源:http://www.cnblogs.com/AndyDai/p/5135294.html 最近在做C / S 开发,需要在C#客户端上传文件到 ...
- ALGO-7_蓝桥杯_算法训练_逆序对
出处:http://blog.csdn.net/enjoying_science/article/details/44114035 (有难度,以后回来填坑) 阅读代码中: #include<st ...
- Spring和Quartz集成
本文转载自:http://blog.csdn.net/u010648555/article/details/54891264 Spring是一个很优秀的框架,它无缝的集成了Quartz,简单方便的让企 ...