最近,项目需要导出excel,之前使用的是PHPExcel。两千多行记录导出很慢,性能很有问题。在网上看看其他导出excel 的方式。发现Spreadsheet_Excel_Writer 是一种方式,看了几个不错的博客,都不是很完整。现在,总结下
一、 php 安装pear
之前对pear的简单理解是,比如require 一个类文件,如果没有指定路径,php引擎会根据php.ini中include_path的设置依次寻找(当前路径、pear目录)
1.1 访问 http://pear.php.net/go-pear ,将页面“另存为” ,文件名可以指定为go-pear.php
1.2 在DOS下执行 php go-pear.php
1.3 提示 PHP 版本太新,去http://pear.php.net/go-pear.phar 下载适合 php 5.4的包,重新安装,然后,回车,回车就好
1.4 设置PATH 变量,双击E:\wamp\wwwPEAR_ENV.reg文件 ,如果出现问题,请参考该博客 http://www.cnblogs.com/bugY/archive/2012/07/06/2578972.html
二、安装OLE-1.0.0RC2 和Spreadsheet_Excel_Writer-0.9.3
pear下Spreadsheet_Excel_Writer下载地址:http://pear.php.net/package/Spreadsheet_Excel_Writer/download
OLE下载地址:http://pear.php.net/package/OLE/download
pear install OLE-1.0.0RC2
pear install Spreadsheet_Excel_Writer-0.9.3
三、安装完成后,重启apache服务器,加载类试试
require_once('pear/Spreadsheet/Excel/Writer.php');
可能出错,还需要修改php.ini 中
output_buffering = On;
include_path = 指定pear所在的目录 (比如我的include_path = ".;c:\php\includes;E:\wamp\www\pear" )
四、 加载类正常了,然后出现调用函数引用传递和静态调用非静态方法的错误,修改对应文件
OLE.php---- function Asc2Ucs($ascii) 改为 static function Asc2Ucs($ascii)
OLE.php---- function LocalDate2OLE($date = null) 改为 static function LocalDate2OLE($date = null)
这样就应该可以了,如果还有错的话,生成的 xsl 文件中是可以看到错误信息的
《PHP Excel类Spreadsheet_Excel_Writer简介》 http://blog.csdn.net/bakeloar/article/details/4759151