diego3 / php-export-data
一个简单库,用于将表格数据导出为Excel兼容的XML、CSV或TSV格式
v1.0.0
2015-09-29 16:12 UTC
Requires
- php: >=5.3.0
- elidickinson/php-export-data: dev-psr4
Requires (Dev)
- phpunit/phpunit: 4.5.*
This package is auto-updated.
Last update: 2024-09-18 17:39:50 UTC
README
php-export-data by Eli Dickinson
http://github.com/elidickinson/php-export-data
在MIT许可下发布: https://open-source.org.cn/licenses/mit-license.php
一个简单库,用于将表格数据导出为Excel兼容的XML、CSV或TSV格式。它支持将导出的数据流式传输到文件或直接作为下载发送到浏览器,因此适用于导出大型数据集(您不会耗尽内存)。
Excel XML代码基于Oliver Schwarz的Excel_XML (http://github.com/oliverschwarz/php-excel)
Composer安装
composer require diego3/php-export-data
如何使用它
// When executed in a browser, this script will prompt for download // of 'test.xls' which can then be opened by Excel or OpenOffice. use Export\ExportDataExcel; // 'browser' tells the library to stream the data directly to the browser. // other options are 'file' or 'string' // 'test.xls' is the filename that the browser will use when attempting to // save the download $exporter = new ExportDataExcel('browser', 'test.xls'); $exporter->initialize(); // starts streaming data to web browser // pass addRow() an array and it converts it to Excel XML format and sends // it to the browser $exporter->addRow(array("This", "is", "a", "test")); $exporter->addRow(array(1, 2, 3, "123-456-7890")); // doesn't care how many columns you give it $exporter->addRow(array("foo")); $exporter->finalize(); // writes the footer, flushes remaining data to browser. exit(); // all done
查看test/目录以获取更多示例。
以下列出了从PHP创建Excel文件的一些其他选项: http://stackoverflow.com/questions/3930975/alternative-for-php-excel/3931142#3931142