achy
achy

Reputation: 31

PHPExcel_IOFactory::load throwing uncaught Exception and caused script halt

i've verified that the file is exists, this is my script to load the document

 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();

    }

i read my log and found, error messages from Excel5.php line 995 with messages contain "Call to a member function getBlipType() on a non-object" as i believed that, the parser try to loads the graphics object and failed. btw i've try to read phpexcel discussion forum, and found nothing about the issue. i don't know if this is a bug or the problem comes from my corrupted excel file. but fortunately i can load and read that file correctly without any error when i try to change my loader script and set my reader setReadDataOnly(true); but another problem is, when working with this method, i cannot read my date column correctly.

my question are, how can i caught this type of error, i've try to catch it but it's not working, script just halt?

please any help, i've read this too. mark baker(the author of phpexcel) explaination about date type column

Upvotes: 0

Views: 1708

Answers (2)

user3619211
user3619211

Reputation: 46

I got the same error message when I tried to read images form an Excel file that contain graphics of "unknown type". So, the solution was to add the missing statement in Excel5.php as follows.

Find and replace:

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

with:

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

That's it! The Excel5.php file is part of the PHPExcel distribution and the line you need to replace varies.

Upvotes: 2

achy
achy

Reputation: 31

i think i just find the solution to my own problem, i posted here which purpose if somebody have similar problem. according to the problem, i just need to know which file is failed to process by phpexcel, and i came up to use php function register_shutdown_function( callback function [, mixed parameter [, mixed ...]] ), i use it like this.

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*/
            }


        }
    }

}

this function is called when fatal error happen. so that i can log any file which raise the fatal error, problem solve. :D

Upvotes: 0

Related Questions