PHP操作Excel类PHP-Excel

本文详细介绍使用PHP类库导出数据至Excel文件的过程。首先创建二维数组存储数据,然后实例化Excel_XML类并传入数组。通过设置类构造函数参数,可自定义字符集、类型识别及工作表标题。最后生成XML/Excel文件,触发浏览器的保存对话框。

To get the export running, first create a two-dimensional
array (please stick to 2 dimensions, the library does not
work with complex arrays):

$a = array();
for($i=0;$i<10;$i++)
        $a[] = array('Cell' . $i);

Instanciate the library and give the array as input:

$xls = new Excel_XML();
$xls->addArray($a);

Generate the XML/Excel file. This method should trigger
the browsers "Save as..." dialog:

$xls->generateXML('test');

Optional values
---------------
1) You may set your own charset in the constructor of
the class:

$xls = new Excel_XML('UTF-8');

2) You may activate/deactivate type identification for
table cells (strings/numbers):

$xls = new Excel_XML('UTF-8', true);

Whereas the values are: 'true' = type identification
active, 'false' (default) = type identification inactive.

3) You may set the worksheet title directly in the
constructor:

$xls = new Excel_XML('UTF-8', true, 'Testsheet');

Problems, Errors, Help

-----------------------------------------------------------------------------------------------------------

 

<?php

// load library
require 'php-excel.class.php';

// create a simple 2-dimensional array
$data = array(
        1 => array ('Name', 'Surname'),
        array('Schwarz', 'Oliver'),
        array('Test', 'Peter')
        );

// generate file (constructor parameters are optional)
$xls = new Excel_XML('UTF-8', false, 'My Test Sheet');
$xls->addArray($data);
$xls->generateXML('my-test');

?>

转载于:https://my.oschina.net/zhangzhihao/blog/70451

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值