Home php PHPEXCEL Error opening XLSX file after saving

PHPEXCEL Error opening XLSX file after saving

Author

Date

Category

Use PHPExcel to keep the file in XLSX format. Saves normally, but when you want to open Excel, gives an error:

in the book “Reserve Report .xlsx” found content, which is not
managed to read. Try
Restore the contents of the book? If you
trust the source of this book,
Click the “Yes” button.

Click Yes – a message is displayed:

Checking at the level
file with subsequent restoration
file. Some fragments of the document
could be restored or removed.

XML is generated with error report:

& lt; xml version = "1.0" encoding = "utf-8" Standalone = "TRUE"? & gt;
& lt; recoverylog xmlns = "http://schemas.openxmlformats.org/spreadsheetml/2006/main" & gt;
  & lt; logfilename & gt; error048360_01.xml & lt; / logfilename & gt;
  & lt; Summary & gt; errors in the file
    "C: \ users \ xxx \ downloads \ report on
    temporary reserves from 01/01/2015
    (6) .xlsx "
  & lt; / summary & gt;
  & lt; additionalinfo & gt;
    & lt; info & gt; a check was performed on
      file level with subsequent
      file restore. Some
      Fragments of the document could be
      Restored or deleted.
    & lt; / info & gt;
  & lt; / additionalinfo & gt;
& lt; / recoverylog & gt;

PHPEXCEL settings:

& lt;?
$ OutputFileType = 'Excel2007';
$ objwriter = phpexcel_iofactory :: CreateWriter ($ ObjPhpexcel, $ OutputFileType);
$ Objwriter- & gt; SetPRecalculateTeformulas (false);
/ * Save the document * /
Header ("Content-Type: Application / vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Header ('Content-Disposition: attachment; filename ='. $ namexls. '.xlsx');

Office 2010 Used.

After all messages, the report opens, and everything is fine with it, as it should be.
Tell me how to get rid of these error messages?


Answer 1, Authority 100%

In general, the problem was decided pretty simple:

It turned out that you need to specify the following combination in the code:

$ objwriter = phpexcel_iofactory :: creatwriter ($ ObjPhpexcel, 'Excel5');
Header ('Content-Type: Application / VND.MS-Excel');

or

$ objwriter = phpexcel_iofactory :: createwriter ($ ObjPhpexcel, 'Excel2007');
Header ('Content-Type: Application / vnd.openxmlformats-officedocument.spreadsheetml.sheet');

I was like this:

$ objwriter = phpexcel_iofactory :: createwriter ($ ObjPhpexcel, 'Excel2007');
Header ('Content-Type: Application / VND.MS-Excel');

What is wrong.


Answer 2

Most likely, it makes sense to cut CSS before generating Excel. And in general, in principle, the same couple of days ago was engaged. Skip the archive with the source and do not forget to specify UTF-8 in the source (without BOM). guide


Answer 3

I had the same problem, and helped this code. After it, the error was not.

mb_internal_encoding ('latin1');

Answer 4

also swore to the generated Excel file when using PHP7. I solved the problem as follows:

  1. Added at the beginning of the MB_INTERNAL_ENCODING script ('Latin1');

  2. Before the file output, add OB_END_CLEAN () so that it turns out:

    ob_end_clean ();
    $ Objwriter- & GT; Save ('php: // output');
    
  3. in the / phpexcel/calculation/functions.php file Commitments Break in the 581th line:

    if (($ value === null) || (IS_FLOAT ($ Value)) || (IS_INT ( $ Value))) {
      Return 1;
     } ELSEIF (IS_BOOL ($ VALUE)) { 
    return 4;
     } elseif (is_array ($ value)) {
      return 64;
      // break; - php7 swears, comment
     } elseif (is_string ($ value)) {
      // Errors
      if ((strlen ($ value) & gt; 0) & amp; & amp; ($ value {0} == '#')) {
       return 16;
      }
      return 2;
     }
     return 0;
    } // function TYPE ()
    

Answer 5

suffered with the same problem
helped by the opencart export import module
https://www.opencart.com/index. php? route = extension / extension / info & amp; extension_id = 17
I picked up a solution using the plug-in method
add exit at the end;

$ objWriter = PHPExcel_IOFactory :: createWriter ($ phpexcel, 'Excel2007');
header ('Content-Type: application / vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header ('Content-Disposition: attachment; filename = "products.xlsx"');
header ('Cache-Control: max-age = 0');
$ objWriter- & gt; setPreCalculateFormulas (false);
$ objWriter- & gt; save ('php: // output');
// without this line when opening the xlsx file an error !!!!!!
exit;

and there is no such problem with xls

can someone comment because there are not enough brains

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions