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

PHP导出Excel 之 Spreadsheet

WBOY
WBOY원래의
2016-06-06 19:46:45934검색

之前看到过好多关于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>


效果图:

PHP导出Excel 之 Spreadsheet

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.