使用phpExcelReader操作excel提示The filename *.xls is not readable的详细解决方法

程序开发中经常会需要我们对office进行操作,比如用户信息需要通过excel导入到数据库。在开源的excel操作类中,有两款产品最受人青睐,一款是phpExcelReader,一款是phpExcel。

通过phpExcelReader读取excel的时候,往往会出现以下各种问题:

1、Deprecated: Assigning the return value of new by reference is deprecated
in Assigning the return value of new by reference is deprecated in…

2、Warning: require_once(Spreadsheet/Excel/Reader/OLERead.php)
[function.require-once]: failed to open stream: No such file or
directory in…

3、Notice: iconv() [function.iconv]: Detected an illegal character in input
string in D:wampwwwphpExcelReaderExceleader.php on line…

4、Fatal error: Maximum execution time of 30 seconds exceeded in …

5、The filename *.xls is not readable

现在我针对以上问题一一解答,给出解决方案

针对第一个报错:

这个是php5.3以后版本的问题,php5.3以下版本不会出现。php5.3开始后,废除了php中的”=&”符号,所以直接用”=”引用即可。

也就是将

$this->_ole =& new OLERead(); // 大约在reader.php第261行

改为:$this->_ole = new OLERead();

第二个报错修改方法:

官方给的phpExcelReader/Excel文件夹中有两个文件,一个是oleread.inc;一个是reader.php。所以只需要将

require_once ‘Spreadsheet/Excel/Reader/OLERead.php’;

改为:require_once ‘oleread.inc’就行了,同时还要注意,linux系统中文件夹大小写也需要统一。

第三个报错的解决方法:

这个错误是用官方给的example里面的编码问题,修改方法是:

将example.php里面的

$data->setOutputEncoding(‘CP1251’);

改为:data>setOutputEncoding(UTF8);//gbkGB2312utf8 data->setOutputEncoding(‘UTF-8’);

第四个报错的解决方法:

demo里面的这个excel文件有错误,自己创建一个就OK了。

第五个报错的解决方法:

最后这个问题有几种可能,按照“The filename *.xls is not readable”英文字面意思是权限问题。如果是权限问题,请给.xls的文件设置777权限,方法不用说了。

大部分开发者看到这个问题都会认为就是权限问题,其实不然。如果权限没问题还报这个错误,那么问题就出在路径上了,很多人都是用的类似这样的路径:/upload/newfile/1447921707/wanhui_user_ipro_1/wanhui_user_ipro/user_exp.xls。在操作文件的时候,这样的路径是不行的,路径前面需要添加网站站点的物理路径。

解决方法:

假如/www/web/wanhui/abc/public_html/是网站的物理路径,那么

data>read( contentfilename);

里面的$contentfilename就应该是:

$contentfilename=/www/web/wanhui/abc/public_html/upload/newfile/1447921707/wanhui_user_ipro_1/wanhui_user_ipro/user_exp.xls;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章