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.

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.