phpexcel导入xlsx文件报错xlsx is not recognised as an OLE file 怎么办

最初的做法

 代码如下
1 include 'classes/PHPExcel/IOFactory.php';
2 $inputFileName = $target;
3
$objReader = new PHPExcel_Reader_Excel5(); 
4 $objPHPExcel = $objReader->load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$count = count($sheetData);
for($i=1;$i<=$count;$i++)
{
 echo (iconv('utf-8','gbk',$sheetData[$i]['A'])).'<hr />';
}

报错

 PHPExcel_Reader_Exception: The filename .1443578799.xlsx is not recognised as an OLE file in Classes\PHPExcel\Shared\OLERead.php on line 89

( ! ) Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'The filename 1443578799.xlsx is not recognised as an OLE file' in Classes\PHPExcel\Shared\OLERead.php on line 89 
( ! ) PHPExcel_Reader_Exception: The filename 1443578799.xlsx is not recognised as an OLE file in Classes\PHPExcel\Shared\OLERead.php on line 89 
Call Stack

碰到这个问题我们是因为xlsx出错了,可能通过类型判断 解决办法如下

 代码如下
1 if( $extension =='xlsx' )
{
 $objReader = new PHPExcel_Reader_Excel2007();
}
else
{
 $objReader = new PHPExcel_Reader_Excel5();
}

这样再操作会发现问题已经解决了。

posted @ 2018-01-23 09:04  追忆丶年华  阅读(1454)  评论(0编辑  收藏  举报