{"id":5546,"date":"2019-09-09T19:14:13","date_gmt":"2019-09-10T00:14:13","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5546"},"modified":"2019-09-11T14:22:03","modified_gmt":"2019-09-11T19:22:03","slug":"corrupted-spreadsheets-from-phpspreadsheet-andphpexcel","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5546","title":{"rendered":"Corrupted Spreadsheets From PHPSpreadsheet (andPHPExcel)"},"content":{"rendered":"<p>I need to deliver Excel files to the browser, so used php:\/\/output as the save location. Does exactly what I want except \u2026<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1025\" height=\"115\" class=\"wp-image-5547\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-1.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-1.png 1025w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-1-300x34.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-1-768x86.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-1-1024x115.png 1024w\" sizes=\"auto, (max-width: 1025px) 100vw, 1025px\" \/><\/p>\n<p>Excel says it has a problem with some of the file content. It\u2019s recoverable \u2013 click \u201cYes\u201d and you\u2019ll see all of the spreadsheet data. But no one is going to want to run a repair on every single file they download from my site!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1197\" height=\"447\" class=\"wp-image-5548\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-2.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-2.png 1197w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-2-300x112.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-2-768x287.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-2-1024x382.png 1024w\" sizes=\"auto, (max-width: 1197px) 100vw, 1197px\" \/><\/p>\n<p>I confirmed the buffer was being cleared, that I didn\u2019t have any extraneous PHP errors getting inserted into the spreadsheet data. My output was clean \u2013 it was also corrupt. I\u2019d actually started using the old PHPExcel module, installed and changed over to PHPSpreadsheet because I know PHPExcel is not maintained. But the problem persisted. I started reading through the docs for PHPSpreadsheet to see if I could find a hint.<\/p>\n<p><a href=\"https:\/\/phpspreadsheet.readthedocs.io\/en\/latest\/topics\/recipes\/&quot; \\l &quot;redirect-output-to-a-clients-web-browser\">https:\/\/phpspreadsheet.readthedocs.io\/en\/latest\/topics\/recipes\/#redirect-output-to-a-clients-web-browser<\/a><\/p>\n<pre><strong>Caution:<\/strong>\r\n\r\nMake sure not to include any echo statements or output any other contents than the Excel file. \r\nThere should be no whitespace before the opening &lt;?php tag and at most one line break after the closing ?&gt; tag \r\n(which can also be omitted to avoid problems). \r\nMake sure that your script is saved without a BOM (Byte-order mark) because this counts as echoing output. \r\nThe same things apply to all included files. \r\nFailing to follow the above guidelines may result in corrupt Excel files arriving at the client browser, \r\nand\/or that headers cannot be set by PHP (resulting in warning messages).<\/pre>\n<p>Do I have more than one newline after the closing \u201c?&gt;\u201d tag? Sure do!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"344\" class=\"wp-image-5549\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-3.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-3.png 818w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-3-300x126.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2019\/09\/word-image-3-768x323.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/p>\n<p>Got rid of the extra newline, and the downloaded file is fine.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I need to deliver Excel files to the browser, so used php:\/\/output as the save location. Does exactly what I want except \u2026 Excel says it has a problem with some of the file content. It\u2019s recoverable \u2013 click \u201cYes\u201d and you\u2019ll see all of the spreadsheet data. But no one is going to want &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[35,820,819],"class_list":["post-5546","post","type-post","status-publish","format-standard","hentry","category-coding","tag-php","tag-phpexcel","tag-phpspreadshet"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5546"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5546\/revisions"}],"predecessor-version":[{"id":5550,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5546\/revisions\/5550"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}