读书人

PHP远程读取excel文件如何读取?

发布时间: 2012-12-31 11:57:52 作者: rapoo

PHP远程读取excel文件,怎么读取??
PHPExcel能远程读取excel文件吗?即读取其他服务器上的文件!

或者有没有其他好的方法能实现?

求方法...

[解决办法]
先用file_get_contents或者curl把文件取回来用phpexcel打开即可
[解决办法]
先把远程的弄到本地里。
最简单代码是:


file_put_contents('abc.xls',file_get_contents('http://www.xx.com/abc.xls'));

[解决办法]
PHPExcel 通过 PHPExcel_Shared_OLERead 类的 read 方法读取文件
但 read 方法里使用了 is_readable 函数来确认文件是否存在,而 is_readable 不能作用于 url
所以不可直接远程读取
但若绕过 is_readable 函数的话,就是可以的
        public function read($sFileName)
{
// Check if file exists and is readable
if(!is_readable($sFileName)) {
throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}

// Get the file data
$this->data = file_get_contents($sFileName);

[解决办法]
直接注释代码就好了嘛
或者试用tempnam生成临时文件,记得要删

读书人网 >PHP

热点推荐