zoukankan      html  css  js  c++  java
  • 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 ClassesPHPExcelSharedOLERead.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 ClassesPHPExcelSharedOLERead.php on line 89 
    ( ! ) PHPExcel_Reader_Exception: The filename 1443578799.xlsx is not recognised as an OLE file in ClassesPHPExcelSharedOLERead.php on line 89 
    Call Stack

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

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

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

  • 相关阅读:
    第十一章关联容器
    第十章泛型算法
    第九章
    第八章
    阅读记录
    java.lang.Class阅读笔记
    java.time包阅读笔记
    CLion运行多个main函数
    c++中lower_bound和upper_bound中的comp参数
    如何写dfs
  • 原文地址:https://www.cnblogs.com/xiaoleiel/p/8333896.html
Copyright © 2011-2022 走看看