PHPEXCEL导入数据库,执行到load导致系统崩溃问题

来源:互联网 发布:株洲网络买花花店 编辑:程序博客网 时间:2024/06/02 01:17

因为之前的一个系统在使用PHPEXCEL导入的时候,出现了系统崩溃的问题,后面经过一步步的分析,在load()里面中断,系统无法响应。
解决这个问题其实很简单。
一般影响这个问题的原因,是你的excel里面的内容有出现特殊的字符。
解决方法:

try {
     $inputFileType = PHPExcel_IOFactory::identify($uploadfile);
     $objReader = PHPExcel_IOFactory::createReader($inputFileType);
     $objReader->setReadDataOnly(true);//只需要添加这个方法
     $objPHPExcel = $objReader->load($uploadfile);
    } catch(Exception $e) {
         die('Error loading file "'.pathinfo($uploadfile,PATHINFO_BASENAME).'": '.$e->getMessage());
    }

其意思就是读取相应的单元格的数据,忽略任何格式的信息。
我们来看下官方的代码。

    /**
     * Read data only?
     * Identifies whether the Reader should only read data values for cells, and ignore any formatting             information;
     * or whether it should read both data and formatting
     * @var boolean
     */
    protected $_readDataOnly = FALSE;

默认使用的是false。

阅读全文
0 0