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

被折叠的 条评论
为什么被折叠?



