【问题标题】:PHPExcel_IOFactory::load throwing uncaught Exception and caused script haltPHPExcel_IOFactory::load 抛出未捕获的异常并导致脚本停止
【发布时间】:2013-07-23 19:35:58
【问题描述】:

我已经验证文件存在,这是我加载文件的脚本

 try{
       $this->obj_global = PHPExcel_IOFactory::load($this->file_name);
       $err_msgs = '';

    }catch(ErrorException $e)
    {
        $err_msgs = $e.getMessage();

    }catch (Exception $e)
    {
        $err_msgs = $e.getMessage();

    }

我阅读了我的日志并发现,来自 Excel5.php 第 995 行的错误消息包含“调用非对象上的成员函数 getBlipType()”,因为我相信,解析器尝试加载图形对象并失败的。 顺便说一句,我尝试阅读 phpexcel 讨论论坛,但没有发现任何有关该问题的信息。我不知道这是一个错误还是问题来自我损坏的 excel 文件。但幸运的是,当我尝试更改加载程序脚本并设置我的阅读器 setReadDataOnly(true); 时,我可以正确加载和读取该文件而不会出现任何错误;但另一个问题是,在使用这种方法时,我无法正确读取我的日期列。

我的问题是,我怎样才能捕捉到这种类型的错误,我试图捕捉它但它不起作用,脚本只是停止了吗?

请帮忙,我也读过这个。 mark baker(the author of phpexcel) explaination about date type column

【问题讨论】:

  • 我认为您希望在 catch 块中使用 $e->getMessage() 而不是 $e.getMessage()
  • 确实,我写错了那种风格(在 jScript 和 php 之间切换,忘记了我的风格)。 :D,但仍然未捕获的异常。 :( 这是一个致命错误导致脚本停止。

标签: php batch-file phpexcel


【解决方案1】:

当我尝试从包含“未知类型”图形的 Excel 文件中读取图像时,我收到了相同的错误消息。所以,解决方法是在Excel5.php中添加缺失的语句如下。

查找和替换:

$BSEindex = $spContainer->getOPT(0x0104);

与:

$BSEindex = $spContainer->getOPT(0x0104);
if (empty($BSEindex)) break;

就是这样! Excel5.php 文件是 PHPExcel 发行版的一部分,您需要替换的行有所不同。

【讨论】:

    【解决方案2】:

    我想我只是找到了解决我自己问题的方法,如果有人遇到类似问题,我会在这里发布。根据问题,我只需要知道phpexcel无法处理哪个文件,我想出了使用php函数register_shutdown_function(回调函数[,混合参数[,混合...]]), 我就是这样用的。

    register_shutdown_function(  "clean_exit" );
    function clean_exit()
    {
        if ( @is_array( $e = @error_get_last() ) ) {
            $code = isset( $e['type'] ) ? $e['type'] : 0;
            $msg = isset( $e['message'] ) ? $e['message'] : '';
            $file = isset( $e['file'] ) ? $e['file'] : '';
            $line = isset( $e['line'] ) ? $e['line'] : '';
    
            /*if fatal error then check, the source of error*/
            if ( $code == 1 ) {
                /*update imported table by current_id_import*/
    
                //look for , if it caused by PHPExcel then update imported table
                $match = preg_match('/phpexcel/i', $file);
                if($match==1)
                {
                  /*if errors caused by phpexcel then do stuff*/
                }
    
    
            }
        }
    
    }
    

    发生致命错误时调用此函数。 这样我就可以记录任何引发致命错误的文件,解决问题。 :D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      相关资源
      最近更新 更多