php excel类 phpexcel使用方法介绍,excelphpexcelphpexcel操作excel可以方便的加入图片,支持jpg gif png格式。
下载地址:http://www.codeplex.com/phpexcel
下面是总结的几个使用方法
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类库不熟悉的朋友,可以阅读下《phpexcel中文帮助手册》中的内容,具体实例大家可以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 formatsn;
$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′);
>>> 更多php教程内容,请关注本站php编程栏目。
加图片
$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());
在默认sheet后,创建一个worksheet
echo date('h:i:s') . create new worksheet objectn;
$objphpexcel->createsheet();
$objwriter = phpexcel_iofactory::createwriter($objexcel, 'excel5');
$objwriter-save('php://output');
phpexcel生成excel不可以读取
总结 php导出excel php导入excel phpexcel使用说明 phpexcel使用手册2009/03/06 上午 02:37方法一:特点,简单,省心,
方法二: 引用google code中推荐的小类库(大体同方法一,比较复杂点)
code.google.com/p/php-excel/downloads/list
方法三: phpexcel 类库,功能强大,支持win excel2003 ,win excel2007.
www.codeplex.com/phpexcel
//设置phpexcel类库的include path
set_include_path('.'. path_separator .
'd:\zeal\php_libs' . path_separator .
get_include_path());
/**
* 以下是使用示例,对于以 //// 开头的行是不同的可选方式,请根据实际需要
* 打开对应行的注释。
* 如果使用 excel5 ,输出的内容应该是gbk编码。
*/
require_once 'phpexcel.php';
// uncomment
////require_once 'phpexcel/writer/excel5.ph......余下全文>>
php中还有什类似phpexcel的东西?介绍一下
phpexcel phpexcel是相当强大的 ms office excel 文档生成类库,当需要输出比较复杂格式数据的时候,phpexcel 是个不错的选择。不过其使用方法相对来说也就有些繁琐。列举以记之。
-- php code --
//设置phpexcel类库的include path
set_include_path('.'. path_separator .
'd:\zeal\php_libs' . path_separator .
get_include_path());
/**
* 以下是使用示例,对于以 //// 开头的行是不同的可选方式,请根据实际需要
* 打开对应行的注释。
* 如果使用 excel5 ,输出的内容应该是gbk编码。
*/
require_once 'phpexcel.php';
// uncomment
////require_once 'phpexcel/writer/excel5.php'; // 用于其他低版本xls
// or
////require_once 'phpexcel/writer/excel2007.php'; // 用于 excel-2007 格式
// 创建一个处理对象实例
$objexcel = new phpexcel();
// 创建文件格式写入对象实例, uncomment
////$objwriter = new phpexcel_writer_excel5($objexcel); // 用于其他版本格式
// or
////$objwriter = new phpexcel_writer_excel2007($objexcel); // 用于 2007 格式
//$objwriter->setoffice2003compatibility(true);
//*************************************
//设置文档基本属性
$objprops = $objexcel->getproperties();
$objprops->setcreator(zeal li); //设置作者
$objprops->setlastmodifiedby(zeal li); //设置最后修改的人
$objprops->settitle(office xls test document); //设置标题
$objprops->setsubject(office xls test document, demo); //设置主题
$objprops->setdescription(test document, generated by ......余下全文>>
http://www.bkjia.com/phpjc/828047.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/828047.htmltecharticlephp excel类 phpexcel使用方法介绍,excelphpexcel phpexcel操作excel可以方便的加入图片,支持jpg gif png格式。 下载地址:http://www.codeplex.com/phpexcel 下...
