Hi all,
I have to replace variables inside a user-submitted xlsx file and am doing it this way:
- Rename the .xlsx to .zip
- Unzip to a temp-folder
- Make the necessary changes
- Zip the files
- Rename the .zip to .xslx
I am using plain ZipArchive in PHP. When I try to open the generated .xlsx in Excel, it fails with a message format or extension invalid
. When I compress the temporary files with WinRAR (as zip), and rename the resulting file to .xlsx, it works. The zip files generated with both methods contain the same data structure and files, but the WinRAR file is slightly bigger (10.2K vs. 10.3K with normal compression).
When viewing the garbled code of the files, I could see that the files appear in a different order, but don't know if that's the cause. Any clue would be greatly appreciated.