Excel export in PHP showing error

Asked

Viewed 662 times

1

I have a problem trying to export file to Excel in PHP. I tried with the library PHPExcel even though it is obsolete/discontinued and I tested with PhpSpreadSheet also. But both presented the same error and only in PHP 7.1.20.

Error presented:

"excel cannot open the file because of the format or extension of file is not valid"

When opened with a text editor, display this message:

Fatal error: Uncaught Phpoffice Phpspreadsheet Writer Exception: Could not open php://output for writing. in C: DESENV Defaultcollection Stcpwebadmin Site www cgi-bin libs vendor phpoffice phpspreadsheet src Phpspreadsheet Writer Xlsx.php:218

Stack trace: < #0 C: DESENV Defaultcollection Stcpwebadmin Site www stcpwebversionxls.php(104): Phpoffice Phpspreadsheet Writer Xlsx->save('php://output')

< #1 {main} thrown in C: DESENV Defaultcollection Stcpwebadmin Site www cgi-bin libs vendor phpoffice phpspreadsheet src Phpspreadsheet Writer Xlsx.php online 218

I tested in versions 7.1.14 and 7.1.17 and worked normally.

You know why?

  • Try editing the generated file with a text editor and put a snippet

  • @Jorgecosta added the message to the body as you requested.

  • What are you using for php wamp server or something ? Put the code you are using to generate the file.

  • Check that you have access with write permissions to the folder for temporary files to know which one to use sys_get_temp_dir

  • @Jorgecosta am using Windows IIS and have write permission in folder

1 answer

0

I think the problem was in downloading PHP, probably must have corrupted some file while downloading. Because I downloaded PHP 7.1.20 again, I pointed to the new folder and now it’s working.

  • I personally think that maybe it was lack of restarting something, or the first download you made was damaged, or maybe you forgot to adjust something on php.ini to use the fileinfo

  • @Guilhermenascimento did the test at another development site with PHP that I had previously downloaded and presented the same problem. After using what I downloaded recently, it worked.

  • Yeah, but things don’t stop working randomly and they don’t work randomly, just because you don’t know what made it work doesn’t mean it happened "alone," as I said, I believe it was more likely that: 1. you have not restarted the http server (apache, ngnix, lighttpd) 2. you forgot to configure the first time the php.ini 3. there may have been some corruption of php when you downloaded it (this is the least likely).

  • It didn’t stop randomly, that’s when I changed the PHP version. And I have the two PHP 7.1.20 files on my computer, if I do the same procedure for both, what I was testing earlier still doesn’t work. As I meant, maybe you didn’t understand, it was probably something that corrupted when I downloaded PHP itself.

  • Dear Ucas, stop or start running randomly, that’s what I said, your reply now STATES that it works in PHP 7.1.20 just to have downloaded again, but this is impossible, That would be something random EXCEPT it’s one of the three points I’ve already said are the possible causes of the error. Understood? Nothing starts to work randomly, it is likely that you forgot to restart something or the other two options I mentioned, there is still a fourth option, but this would be on linux servers, which is not your case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.