2023年php操作excel文件实用
在日常学习、工作或生活中,大家总少不了接触作文或者范文吧,通过文章可以把我们那些零零散散的思想,聚集在一块。相信许多人会觉得范文很难写?以下是我为大家搜集的优质范文,仅供参考,一起来看看吧
php操作excel文件篇一
phpexcel是用来操作officeexcel文档的一个php类库,它基于微软的openxml标准和php语言。可以使用它来读取、写入不同格式的`电子表格。下面小编给大家整理了phpexcel使用方法,供大家参阅。
<
equire_once '';
require_once'phpexcel/writer/'; 用于其他低版本xls
or
require_once'phpexcel/writer/'; 用于excel-2007 格式
创建一个处理对象实例
$objexcel = new phpexcel();
创建文件格式写入对象实例, uncomment
$objwriter = newphpexcel_writer_excel5($objexcel); 用于其他版本格式
or
$objwriter = newphpexcel_writer_excel2007($objexcel); 用于2007 格式
$objprops = $objexcel->getproperties ();
设置创建者
$objprops->setcreator ( 'xululu');
设置最后修改者
$objprops->setlastmodifiedby("xululu");
描述
$objprops->setdescription("摩比班级");
设置标题
$objprops->settitle ( '管理器' );
设置题目
$objprops->setsubject("officexls test document, demo");
设置关键字
$objprops->setkeywords ( '管理器' );
设置分类
$objprops->setcategory ( "test");
工作表设置
$objexcel->setactivesheetindex( 0 );
$objactsheet = $objexcel->getactivesheet ();
单元格赋值 例:
$objactsheet->setcellvalue ( 'a1', 'id');
$objactsheet->setcellvalue ( 'b1', 'hashcode');
$objactsheet->setcellvalue ( 'c1', 'modelname');
$objactsheet->setcellvalue ( 'd1', 'indexname');
$objactsheet->setcellvalue('a1', '字符串内容'); 字符串内容
$objactsheet->setcellvalue('a2', 26); 数值
$objactsheet->setcellvalue('a3', true); 布尔值
$objactsheet->setcellvalue('a4', '=sum(a2:a2)'); 公式
自动设置单元格宽度 例:
$objactsheet->getcolumndimension('a')->setautosize(true);
手动设置单元格的宽度 例:
$objactsheet->getcolumndimension('a')->setwidth(10);
导出的文件名
$outputfilename = iconv ( 'utf-8', 'gb2312', 'xululu_'. time() . '.xlsx' );
直接导出文件
$objwriter->save ( $outputfilename );
文件直接输出到浏览器
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/-excel');
header ( 'content-type:application/octet-stream');
header ( 'content-type:application/download');
header ( 'content-disposition:attachment;filename='. $outputfilename );
header ( 'content-transfer-encoding:binary');
$objwriter->save ( 'php:output');
其他设置:
显式指定内容类型
$objactsheet->setcellvalueexplicit('a5','847475847857487584',
phpexcel_cell_datatype::type_string);
合并单元格
$objactsheet->mergecells('b1:c22');
分离单元格
$objactsheet->unmergecells('b1:c22');
得到单元格的样式
$objstylea5 = $objactsheet->getstyle('a5');
设置字体
$objfonta5 = $objstylea5->getfont();
$objfonta5->setname('courier new');
$objfonta5->setsize(10);
$objfonta5->setbold(true);
$objfonta5->setunderline(phpexcel_style_font::underline_single);
$objfonta5->getcolor()->setargb('ff999999');
设置对齐方式
$objaligna5 = $objstylea5->getalignment();
$objaligna5->sethorizontal(phpexcel_style_alignment::horizontal_right);
$objaligna5->setvertical(phpexcel_style_alignment::vertical_center);
设置边框
$objbordera5 = $objstylea5->getborders();
$objbordera5->gettop()->setborderstyle(phpexcel_style_border::border_thin);
$objbordera5->gettop()->getcolor()->setargb('ffff0000'); color
$objbordera5->getbottom()->setborderstyle(phpexcel_style_border::border_thin);
$objbordera5->getleft()->setborderstyle(phpexcel_style_border::border_thin);
$objbordera5->getright()->setborderstyle(phpexcel_style_border::border_thin);
设置填充颜色
$objfilla5 = $objstylea5->getfill();
$objfilla5->setfilltype(phpexcel_style_fill::fill_solid);
$objfilla5->getstartcolor()->setargb('ffeeeeee');
从指定的单元格复制样式信息.
$objactsheet->duplicatestyle($objstylea5,'b1:c22');
*************************************
添加图片
$objdrawing = new phpexcel_worksheet_drawing();
$objdrawing->setname('zealimg');
$objdrawing->setdescription('image ed byzeal');
$objdrawing->setpath('./');
$objdrawing->setheight(36);
$objdrawing->setcoordinates('c23');
$objdrawing->setoffsetx(10);
$objdrawing->setrotation(15);
$objdrawing->getshadow()->setvisible(true);
$objdrawing->getshadow()->setdirection(36);
$objdrawing->setworksheet($objactsheet);
添加一个新的worksheet
$objexcel->createsheet();
$objexcel->getsheet(1)->settitle('测试2');
保护单元格
$objexcel->getsheet(1)->getprotection()->setsheet(true);
$objexcel->getsheet(1)->protectcells('a1:c22','phpexcel');
phpexcel在cakephp中应用:
在vendors/下创建一个文件夹excel,将phpexcel的目录如下:
在要调用的controller下的方法写如下代码:
app::import ( 'vendor', 'excel', array ('file' =>'' ) );后,就可以实例化phpexcel;具体跟以上情况一样。
<
s("content_relate");【phpexcel使用方法有哪些】相关文章:
科目三考试掉头有哪些步骤有哪些07-16大学考证有哪些 大学最实用证书有哪些09-20php用法有哪些11-18java有哪些优势10-04 photoshop有哪些功能11-13自考有哪些专业06-262017职称考试有哪些09-24职称考试有哪些专业09-24会计类证书有哪些?05-17
-
2023年php截取指定字符串 php截取网页指定内容实用
-
2023年月度工作计划表 excel实用(五篇)
-
2023年excel实验报告心得 excel的实训心得(六篇)
-
最新php开发工程师工作职责 php软件开发主管(二十三篇)
-
最新php paypal 用php写的网站通用
-
php实现排序算法 php排序数组汇总
-
2023年excel基础知识归纳 excel基础知识及应用精选
-
2023年一件事作文七篇(实用)
-
2023年初中作文课件ppt实用
-
2023年武术体操实用
-
2023年excel库存管理表 库存管理课件(5篇)
-
2023年linux系统怎么添加计划任务执行php文件命令精选
-
2023年深度解析php就业形势报告实用
-
2023年一件傻事作文300字 一件傻事作文400字作文实用
-
怎样熟练操作办公软件 办公软件使用技巧
-
2023年php实训总结心得(3篇)
-
2023年一件写事作文350字实用
-
2023年别人做的一件事作文作文实用
-
最新c语言文件的基本操作模板
-
2023年一件感人作文300字 一件感人作文600字实用(4篇)
-
2023年国贸实操课心得 国贸专业软件(十三篇)
-
2023年php中级工程师标准 php工程师工作内容(五篇)
-
最新php调用java方法 php调用类中的函数优质
-
曹操 曹操的诗高中实用
-
2023年excel自定义表格制作 excel怎么自定义打印优质
-
2023年武术操的作文 武术操训练记作文汇总
-
2023年php header refresh优秀
-
2023年感人两件事的作文500字实用
-
2023年做广播体操作文300字通用
-
2023年word和excel打开很慢通用
-
2023年PHP岗位职责 初级php工程师简历(20篇)
-
2023年受委屈的一件事作文 受委屈的一件事作文400字实用
-
2023年写一件趣事作文字 写一件趣事作文字(实用二十五篇)
-
2023年一件搞笑的事作文300字 一件搞笑的事作文600字实用
-
2023年一件有趣的事 小学作文 一件有趣的事作文500字实用
-
一件快的事作文作文字 一件快乐事实用
-
2023年网签合同操作流程(实用14篇)
-
2023年php页面跳转方法 php自动跳转页面模板
-
2023年出现频率最高的php面试题怎么做实用
-
2023年excel会计实训心得体会(11篇)
-
最新曹操杀华佗典故原文 曹操杀华佗原文实用
-
2023年做操检讨书(实用13篇)
-
2023年曹操诗词首(实用17篇)
-
化学实验操作注意事项语言 化学实验操作要点实用
-
2023年这件事令我伤心作文350字实用
-
2023年最开心的一件事作文200字实用
-
2023年一件令我感动事作文500字实用
-
2023年感动一件事作文300字实用(五篇)
-
2023年暑假里的一件事初一作文 暑假的一件事作文七篇(实用)
-
2023年作文 一件有意义的事 作文一件有意义的事情五篇(实用)
-
2023年写校园中的一件事的作文 写校园里一件事的作文实用
-
操作工个人年终总结简短 操作员工年终工作总结实用
-
php sockets模板
-
2023年php产品开发主管 php开发专员(二十一篇)
-
2023年操作技术员岗位职责五篇(实用)
-
2023年年度工作计划表excel(七篇)
-
2023年php fpm性能调优模板
-
2023年php数据统计图优秀
-
2023年php与javascript的区别精选
-
作文一件好事字 一件好事情作文(实用4篇)
-
2023年excel会计实训心得体会(3篇)
-
PHP岗位职责 php工程师工作内容(18篇)
-
最新lng的操作规程 冲床操作规程(实用9篇)
-
最新操作员工作总结字 操作员工作总结实用
-
2023年一件我感动的事情作文六年级作文字实用
-
2023年简单易操作的装修设计软件 装修自行设计软件优质
-
2023年php就业前景及就业分析报告 php工作前景怎么样大全
-
2023年金蝶软件遇到的常见问题及解决方法 金蝶kis财务软件实务操作汇总
-
2023年后悔的一件事的作文400字 后悔的一件事的作文(实用3篇)
-
2023年班级跑操口号(实用8篇)
-
2023年excel会计实训心得体会(三篇)
-
2023年php自学路线汇总
-
2023年科目四考试操作流程 科目四的考试流程与操作方法实用
-
2023年会计电算化考试实务操作题实用(6篇)
-
一件手工作品作文字 一件手工作品作文二年级3篇(实用)
-
2023年高三操行评语(实用14篇)
-
2023年广播体操教案(实用17篇)
-
最新作文《一件小事》实用
-
2023年令我开心的一件的作文实用(七篇)
-
2023年一件难忘的事作文300字22篇(实用)
-
2023年为妈妈做的一件事作文350字实用
-
2023年年度工作计划表excel(15篇)
-
php职业规划
-
2023年一件令我后悔的事初中作文实用
-
2023年一件让我高兴事作文字(实用七篇)
-
2023年难忘的一件事作文600字免费实用
-
2023年一件让我感动的事作文300字实用
-
2023年我总想着这件事作文实用(三十篇)
-
2023年暑假我的一件事作文字(实用五篇)
-
2023年一件感人的事作文400字实用(3篇)
热点推荐
上一篇:最新青岛的标志建筑(五篇)