PHPExcel 在linux下输出excel

[url=http://blog.c3crm.com/node/820]http://blog.c3crm.com/node/820[/url]

起初用1.7.6的不行,windows正常,linux无法输出excel..
只好按照上文换用1.7.2...ok了

[quote]PHPExcel1.7.2在windows上部署使用没有任何问题,但是在Linux服务器上却遇到了奇怪的问题,一直提示:

Warning: require_once() [function.require-once]: URL using bad/illegal format or missing URL in /var/www/Classes/PHPExcel.php on line 50

经过google搜索,有的同学通过升级到PHP5.3.1版本解决,但易客CRM用的PHP5.2.x,不能通过此方法解决,皇天不负有心人,终于找到了解决方法,原来只需注释掉一行代码即可。

解决方法:
把 PHPExcel.php 文件里面的 require_once ‘PHPExcel/Shared/ZipStreamWrapper.php’; 这行代码注释掉即可,估计和zip相关的程序有关。

在此感谢Google和PHPChina。

PS:易客CRM中有关Excel的处理将全部转向PHPExcel库。[/quote]

看了看PHPExcel 1.7.6的install.txt...原来是要输出Excel2007格式的xsx,要有php_zip的支持.
要有php_zip模块....
[url]http://blog.csdn.net/binger819623/article/details/6228968[/url]
[url]http://yang2001.blog.51cto.com/25307/212322[/url]
[url]http://hi.baidu.com/ubuntu2me/blog/item/c41a0211920464f0c3ce79d1.html[/url]
[quote]
1、依次运行以下命令:
wget http://pecl.php.net/get/zip-1.8.10.tgz //貌似已经出新版本了zip1.10.2.tgz
tar zxvf zip-1.8.3.tgz
cd zip-1.8.3
/usr/local/php/bin/phpize (对应的phpize路径)(安装好的php位置)
configure --with-php-config=/usr/local/php/bin/php-config (对应的php-config路径)(php-config文件名不能更改)
make
make install
//此时会在zip/modules/下生成一个zip.so文件,将它拷贝到make之后给的一个路径下,如有同名的,覆盖之。

2、生成的模块路径:
/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/zip.so (对应的extensions路径)

3、修改php.ini
extension_dir = "./"修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
增加extension=zip.so

4、重启apache
apache2/bin/apachectl restart

==========================================

php 利用ZipArchive 实现文件打包



$filename = "./test/test.zip"; //最终生成的 文件名(含路径)  
if(!file_exists($filename)){
//重新生成文件
$zip = new ZipArchive();//使用本 类,linux需开启 zlib,windows需取消php_zip.dll前的注释
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit('无法打开文件,或 者文件创建失败');
}
foreach( $datalist as $val){
$attachfile = $attachmentDir . $val['filepath']; //获取原始 文件路径
if(file_exists($attachfile)){
$zip->addFile( $attachfile , basename($attachfile));//第二个参 数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下
}
}
$zip->close();//关闭
}
if( !file_exists($filename)){
exit("无法找到文件"); //即使创建,仍有可能失败。。。。
}
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filename)); //文件名
header("Content-Type: application/zip"); //zip格式的
header("Content-Transfer-Encoding: binary"); //告诉浏览 器,这是二进制文件
header('Content-Length: '. filesize($filename)); //告诉浏览 器,文件大小
@readfile($filename);

[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值