PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

Strange output quirks in XLS format #720

Open ralplpcr opened 9 years ago

ralplpcr commented 9 years ago

I've been using PHPExcel for a while, and although I love it, there is one quirk that has been driving me crazy - - so I'm hoping someone on here has a suggestion how to work around it?

I've been using PHPExcel on a server to generate XLS files for upload into our IT system. The problem is that there is something about the PHPExcel output that isn't quite exactly the same. If I try to upload one of the files directly into our IT system, it will fail. However, if I open the file in Excel and then immediately re-save it, it works perfectly? I've been using PHPExcel for a while, and although I love it, there is one quirk that has been driving me crazy - - so I'm hoping someone on here has a suggestion how to work around it?

I've been using PHPExcel on a server to generate XLS files for upload into our IT system. The problem is that there is something about the PHPExcel output that isn't quite exactly the same. If I try to upload one of the files directly into our IT system, it will fail. However, if I open the file in Excel and then immediately re-save it, it works perfectly?

The file looks identical to the naked eye, and even the file size being reported shows as the same. But if I run an "FC" in Windows against the 2 files, it does identify some differences.

Short of continuing to open/resave files, is there anything that can be done to adjust the output to a more "true" Excel file? (and yes, I've already explored automating the open/resave... but I'd rather not have to if at all possible)

Comparing files C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls and C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS ***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

€¤ZЯˆÐ@

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

€\±¯ˆÐ@


***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

€¤ZЯˆÐ

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

€\±¯ˆÐ


***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

;óЯˆÐ ;óЯˆÐ

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

©ô±¯ˆÐ ©ô±¯ˆÐ

The file looks identical to the naked eye, and even the file size being reported shows as the same. But if I run an "FC" in Windows against the 2 files, it does identify some differences.

Short of continuing to open/resave files, is there anything that can be done to adjust the output to a more "true" Excel file? (and yes, I've already explored automating the open/resave... but I'd rather not have to if at all possible)

Comparing files C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls and C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS ***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

€¤ZЯˆÐ@

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

€\±¯ˆÐ@


***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

€¤ZЯˆÐ

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

€\±¯ˆÐ


***\ C:\USERS\Me\DESKTOP\WKFILE\test_no_resave.xls

;óЯˆÐ ;óЯˆÐ

***\ C:\USERS\Me\DESKTOP\WKFILE\TEST_WITH_RESAVE.XLS

©ô±¯ˆÐ ©ô±¯ˆÐ

MarkBaker commented 9 years ago

So you're basically saying that there's a fault somewhere in the Excel5 Writer..... that doesn't really narrow anything down at all.... I guess I can look at the writer and make a few arbitrary changes in the hope that it fixes things for some external reader application that I have no access to for testing, and hope that it doesn't actually break anything in the process

ralplpcr commented 9 years ago

Hi Mark, Thanks for your reply. Yes, I know it's somewhat vague....I'm sorry I can't provide you direct access to upload/test, but I could provide you sample files if that'd help?

I'm currently using PHPExcel 1.78 on a Windows 2008 server running PHP/MySQL. It works by taking an existing (working) file, uploading into a temporary database to enable manipulation of some of the data, then outputting to a new version for upload into the IT system. I plan on updating to PHPExcel to version 1.80 tomorrow to see if that makes any difference. It is quite frustrating, though, since the output seems identical in every way with the only difference being these "mystery bits" that change somehow when saved in Excel.
If it helps any, the IT application is using a Java uploader - - but I've got no further info as to how it's coded or what it's checking that causes the failure. I have also reached out to our IT department to ask if they could provide more info, but thus far have gotten very little useful from them.

And yes, I do realize that Excel is proprietary code...and that you (& the other contributors) have done a truly remarkable job in making it work. So thank you! :) And please don't change anything to risk breaking things. I just wish I knew what it is that's causing the error? I wasn't sure if there was an alternate export method that might make a difference - - I'm currently using the following, which seems pretty straightforward:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output');

I'll post back after I can upgrade the PHPExcel, and see if that makes any difference.

MarkBaker commented 9 years ago

Certainly there have been changes between 1.7.8 and the latest 1.8.1 release (or even the develop branch on github)... including a couple of minor changes to the BIFF Writer.

There will always be some differences between a file saved in MS Excel and one created by PHPExcel, such as the created/modified timestamps.... without having a complete file, it's difficult to identify those differences, because the offsets aren't consistent but dependent on various content elements within the file (such as the length of document properties like subject and title)

ralplpcr commented 9 years ago

Unfortunately, the change to the latest 1.8 (as downloaded by the ZIP from this site) did not make a difference. :( The upload still failed, with a very useless Java error. uselessjavaerror

To look at the two files, they seem identical - but there is obviously still something just different enough to prevent the BIFF output from working. I've contacted our local IT in the hopes that they can provide more info.

I don't know that it'll help, but here are the two files I tested today. The "output_" version is the PHPExcel output, while the other is after opening/saving. It was created by doing nothing other than uploading and exporting - no other changes were made. testfiles (Save, then rename as .ZIP to get the files)

Keeping my fingers crossed IT can tell me why the Java code is failing (and hopefully fix it)!

ralplpcr commented 8 years ago

FYI - I've managed to create a workaround for the time being using the "unoconv" functions in Libreoffice. Basically, instead of creating a BIFF file, I now create an Excel2007 format file, save it, and run it through Libreoffice to convert to Excel5 before downloading. It's a bit clunky, but it does the trick.

If the BIFF writer can be updated to fix the output, I'd much prefer to do that... but at least for now it's less critical. Please let me know if any updates are made to the Excel5 writer - - I'd be more than happy to provide feedback?