phpexcel导入xlsx文件报错xlsx is not recognised as an OLE file 怎么办
最初的做法
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7931')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7931>include 'classes/PHPExcel/IOFactory.php';
$inputFileName = $target;
$objReader = new PHPExcel_Reader_Excel5();
$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出错了,可能通过类型判断 解决办法如下
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2974')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2974>if( $extension =='xlsx' )
{
$objReader = new PHPExcel_Reader_Excel2007();
}
else
{
$objReader = new PHPExcel_Reader_Excel5();
}
这样再操作会发现问题已经解决了。
您可能感兴趣的文章:
phpexcel导入xlsx文件报错xlsx is not recognised as an OLE file 怎么办
PHP导出EXCEL的简单范例 使用phpexcel类库导出excel
phpexcel导入excel到数据库的代码
php语言怎么做表格
phpExcel导出excel加超级链接的实例代码
TP5(layui)excel导入
【PHP】利用phpspreadsheet将数据输出到Excel文件
TP5.0 PHPExcel 数据表格导出导入
phpExcel类的使用方法分享
phpexcel导出数据的实例代码