Home > Backend Development > PHP Tutorial > PHP导出Excel 之 Spreadsheet_Excel_Writer_PHP

PHP导出Excel 之 Spreadsheet_Excel_Writer_PHP

WBOY
Release: 2016-06-01 12:21:18
Original
987 people have browsed it

Excel

之前看到过好多关于PHP导出Excel的文章,自己也通过不少方法实现过,

例如,echo一个Table,然后将header修改为Excel即可。

其实在众多方法中感觉Pear中的Spreadsheet_Excel_Writer很是好用。

关于Spreadsheet_Excel_Writer的安装本文不予介绍,可通过Google找到

答案:) 也可参考: http://pear.php.net/package/Spreadsheet_Excel_Writer/download

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

效果图:

2009-7-28-11.40.46

当然,Spreadsheet_Excel_Writer的设置远远不止这些,详细介绍请参考:

http://pear.php.net/package/Spreadsheet_Excel_Writer/docs

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template