Reputation: 958
I'm trying to load an excel file to be read with PHPExcel reader object:
$inputFileName = $_FILES['excelimportfile']['tmp_name'];
//Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
}catch(Exception $e) {
$this->session->set_flashdata(
'error','Error loading file "'.
pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()
);
redirect('admin/zipcode');
}
But who's gonna throw the exception? this $objPHPExcel = $objReader->load($inputFileName); line should have been used to generate the exception i think. eg:
$objPHPExcel = $objReader->load($inputFileName);
if(!$objPHPExcel) throw new Exception($objPHPExcel->load_error(),1);
But I found nothing like this anywhere. What to do now???
Upvotes: 0
Views: 3325
Reputation: 212412
Code within the PHPExcel library itself throws exceptions rather than returns false as an error status as your last comment seems to suggest that it should; and which suggests that you don't really understand how exceptions work or what their purpose is.
The exceptions that PHPExcel throw from anywhere within the library can be caught and handled by your code, no matter where in the library they are thrown from
There's a whole host of logic in the load() method that can throw an exception (malformed files being one example), but also logic in identify() that can throw an exception too (if the specified file doesn't exist, or can't be read, then the identify() method will throw an exception)....
but it's difficult to understand exactly what you're asking. If you look at the code for the readers, the methods within those classes that can throw an exception are all documented in the phpdoc blocks, and you can see in the class code where exceptions are actually thrown.
Upvotes: 0