0

Hi!
Long time no post, mostly because I've had to put the mobile coding aside for my real job. Plus some home brewing. And lots of pinball.
I have run into a problem. I am developing an application where an Excel spreadsheet (or tab-delimited text file) can be read in and used as data with the MySQL. This works, except:

I want to be able to start with the Excel2007 reader against the imported Excel spreadsheet. If this fails then the Excel5 reader can generally read anything the Excel2007 reader can't.

My big problem is there doesn't seem to be a graceful way of evaluating this. I'm currently trying something like this:

 if (($new_ext=="xls") or ($new_ext=="xlsx")) {
  try {
   $objReader=PHPExcel_IOFactory::createReader('Excel2007');
   $objPHPExcel=$objReader->load($uploadFilename); }
  catch (Exception $e) {
   $objReader=PHPExcel_IOFactory::createReader('Excel5');
   $objPHPExcel=$objReader->load($uploadFilename); } }

Invoking the reader doesn't cause the error, loading it does.

Short of just analyzing the first 128 bytes of the file, is there a way to try another reader if another one fails?

Thanks!
Steve
PS: If you're in Seattle, send me a message and we'll geek out over beer and pinball.

2
Contributors
2
Replies
9
Views
4 Years
Discussion Span
Last Post by LaughingOtter
1

I want to be able to start with the Excel2007 reader against the imported Excel spreadsheet. If this fails then the Excel5 reader can generally read anything the Excel2007 reader can't.

Have you post this question on the PHPExcel forum? The reason is that it's their software and product.

I think someone from there can help you with this.

I think the issue you are having is this:

http://phpexcel.codeplex.com/workitem/17263

I have used PHPExcel and also help members with this but in your case it's not code related but more related to the file.

Edited by LastMitch: grammer

1

Very close!
A quick look-around from there got me the exact answer I needed:

 if (($new_ext=="xls") or ($new_ext=="xlsx")) {
  $inputFileType=PHPExcel_IOFactory::identify($uploadFilename);
  $objReader=PHPExcel_IOFactory::createReader($inputFileType); 
  $objPHPExcel=$objReader->load($uploadFilename);
  ...blahblahblah...

Thanks for pointing me in the right direction, LastMitch!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.