Home > php教程 > php手册 > PHP导出Excel 之 Spreadsheet

PHP导出Excel 之 Spreadsheet

WBOY
Release: 2016-06-06 19:46:45
Original
950 people have browsed it

之前看到过好多关于PHP导出Excel的文章,自己也通过不少方法实现过, 例如,echo一个Table,然后将header修改为Excel即可。 其实在众多方法中感觉Pear中的Spreadsheet_Excel_Writer很是好用。 关于Spreadsheet_Excel_Writer的安装本文不予介绍,可通过Google

之前看到过好多关于PHP导出Excel的文章,自己也通过不少方法实现过,
例如,echo一个Table,然后将header修改为Excel即可。
其实在众多方法中感觉Pear中的Spreadsheet_Excel_Writer很是好用。
关于Spreadsheet_Excel_Writer的安装本文不予介绍,可通过Google找到
答案:) 也可参考: http://pear.php.net/package/Spreadsheet_Excel_Writer/download

<span></span>php<br><span>//调用Writer.php</span><br><span>require_once</span> '<span>Spreadsheet/Excel/Writer.php</span>';<br><span>//创建Workbook</span><br>$workbook = new Spreadsheet_Excel_Writer();<br><span>//定义导出Excel文件名</span><br>$workbook-><span>send</span>('<span>test.xls</span>');<br><span>//创建Worksheet</span><br>$worksheet =& $workbook->addWorksheet('<span>My first worksheet</span>');<br><span>//设置字体大小</span><br>$format_column = & $workbook->addformat(<span>array</span>('<span>Size</span>'=>9,'<span>Bold</span>'=>1));<br><span>//数据写入</span><br><span>//标题行(第一行)</span><br>$worksheet-><span>write</span>(0, 0, '<span>Name</span>', $format_column);<br>$worksheet-><span>write</span>(0, 1, '<span>Age</span>', $format_column);<br><span>//第一个人(第二行)</span><br>$worksheet-><span>write</span>(1, 0, '<span>John Smith</span>');<br>$worksheet-><span>write</span>(1, 1, 30);<br><span>//第二个人(第三行)</span><br>$worksheet-><span>write</span>(2, 0, '<span>Johann Schmidt</span>');<br>$worksheet-><span>write</span>(2, 1, 31);<br><span>//第三个人(第四行)</span><br>$worksheet-><span>write</span>(3, 0, '<span>Juan Herrera</span>');<br>$worksheet-><span>write</span>(3, 1, 32);<br><span>//关闭Workbook</span><br>$workbook-><span>close</span>();<br><span>?></span>
Copy after login


效果图:

PHP导出Excel 之 Spreadsheet

当然,Spreadsheet_Excel_Writer的设置远远不止这些,详细介绍请参考:
http://pear.php.net/package/Spreadsheet_Excel_Writer/docs

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template