PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

Issue generating files with PHP 7 #1264

Closed juliogm12 closed 7 years ago

juliogm12 commented 7 years ago

Hello,

I am writing a website that reads and writes Excel files and am using this framework. I am facing a big problem trying to generate a file. When I first started using PHPExcel I was working on it under PHP 5.6, then our host changed to PHP 7. We have changed our code to make it work on PHP 7 and that's when we noticed that PHPExcel writer is no longer generating files. Whenever I try to open a file generated by PHPExcel Excel tells me the file seems to be corrupted.

This is an important issue for me, can you please help me? Thanks!

PS: I am creating the files using the code used in the Examples folder for xlsx files, same headers.

robregonm commented 7 years ago

Not sure if that's a related issue, however, my bin file starts like this (the one I generated locally and open without issues):

50 4B 03 04 14 00 00 00  08 00 D9 5A F5 4A 19 39  PK...... ...Z.J.9
E2 60 93 01 00 00 EF 0C  00 00 13 00 00 00 5B 43  .`...... ......[C

But the corrupted file starts like this:

50 4B 03 04 14 00 00 00  08 00 97 5C F5 4A 19 39  PK...... ...\.J.9
E2 60 93 01 00 00 EF 20  00 00 13 00 00 00 5B 43  .`.....  ......[C

The differences are highlighted like this

Thought? Ideas?

robregonm commented 7 years ago

Notice that this is not happening to ALL the exported files, but just one of them (when it generates files more than 65kB: not exactly but estimated). I checked that no HTML code is injected or something like that, because I compared the files at a binary level, and the changes are very subtle (those I highlighted in my previous post)

I'm using PHP 7.1 (in both local and prod) And the installed extensions look similar. The only noticeable differences are the Ubuntu version (16.04 in my local environment and 14.04 in production) and the available memory (16GB local env, 512 MB in production)

juliogm12 commented 7 years ago

Hello robregonm. The funny thing is that for me the writer doesn't write anything to the file, yet the file is still corrupted. Not only that but when I tell the file generating the file to echo something usually that thing is echoed along with gibberish which represents the data written on the file. Not anymore and when I open the .xlsx file on Notepad++ the file is blank.

juliogm12 commented 7 years ago

Also, for me at least, this happens to all files that worked pre-PHP7

PowerKiKi commented 7 years ago

@robregonm and @juliogm12 try to remove all HTTP headers and switch to HTML writer and triple check that PHP error reporting is at its maximum and that there is not a single warning and that the generated HTML is correct according to your expectation.

If that leads to nothing, try to switch the ZIP lib used with something like:

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
juliogm12 commented 7 years ago

@PowerKiKi Pardon my ignorance, but when you say "HTMl writer" do you mean the program I use to code or a built in writer on HTML code?

PowerKiKi commented 7 years ago

nope, more like:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');

This will output the first sheet of Excel file as an HTML table. Quite convenient for debugging things...

juliogm12 commented 7 years ago

I did as you suggested and the data is displayed beautifully. Before I had

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

juliogm12 commented 7 years ago

Hello again @PowerKiKi , I was wondering how I could use this to debug. Thanks!

juliogm12 commented 7 years ago

If anyone is interested to know: I fixed the issue. It seems the files that create the file became corrupted to I downloaded them again and overwrote them. Thank you all for your help