0

The question is simple : how to load this Excel workbook (http://wftda.com/stats/wftda-stats-book.xlsx) with PHP Excel without throwing any errors ?

I use the following code (which is more or less the mwe explained in the doc):

$inputFileType = 'Excel2007';

$inputFileName = path_to/wftda-stats-book.xlsx';

//Create a new Reader of the type defined in $inputFileType
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

//Load $inputFileName to a PHPExcel Object
$objPHPExcel = $objReader->load($inputFileName);

After 5 seconds or so of treatment, I get the following errors :

Notice: Trying to get property of non-object in /srv/web/www/dev/arbitrage/_inc/lib/PHPExcel/Classes/PHPExcel/Reader/Excel2007.php on line 1378
Warning: Invalid argument supplied for foreach() in /srv/web/www/dev/arbitrage/_inc/lib/PHPExcel/Classes/PHPExcel/Reader/Excel2007.php on line 1378
Notice: Undefined offset: 0 in /srv/web/www/dev/arbitrage/_inc/lib/PHPExcel/Classes/PHPExcel/Reader/Excel2007.php on line 1394
Fatal error: Call to a member function attributes() on a non-object in /srv/web/www/dev/arbitrage/_inc/lib/PHPExcel/Classes/PHPExcel/Reader/Excel2007.php on line 1396

The part of the code where the errors lie seems to be related to vml relationships, whatever that is...

Silverspur
  • 891
  • 1
  • 12
  • 33
  • Looks like a corrupted xlsx file.... the previous block of code has identified that there are images referenced in the a worksheet in that file, but the actual images themselves don't exist in the file. Was the file created using MS Excel? And if so, which version? – Mark Baker Apr 03 '14 at 15:17
  • I see. Unfortunately, I'm not the author of this file, so I can not answer you question for sure, but I am pretty confident MS Excel was used. Which version, I do not know. Would opening the document with a recent MS Excel and save it back solve the problem ? – Silverspur Apr 03 '14 at 15:24
  • That's impossible to say; somehow there's a corruption of the data in the file that MS Excel itself looks like it has a fallback to allow, but that PHPExcel isn't written to handle.... but without a test file I don't know exactly what to look for and can't put in any error handling – Mark Baker Apr 03 '14 at 16:52
  • Ok, so I have investigate a bit further. There are two problems. The first one is that, for each vml drawing, there were not an associated relationship file. After having added the missing ones, the first two error messages disappeared. The second issue occurs lines 1392+. The code is looking for a v:imagedata tag within a v:shape tag inside the vml drawing file. For some drawings in my xlsx file, such a tag does not exist. I do not know if this qualifies as "file corruption" or if this is a normal case not handled by PHPExcel. Could you enlighten me on that ? – Silverspur Apr 15 '14 at 15:02

1 Answers1

0

You have to include phpexcel libary in libary folder like this:

$this->load->libary('PHPExcel);

download phpexcel and paste it into libary folder.