views:

22

answers:

0

Hi all,

I have to replace variables inside a user-submitted xlsx file and am doing it this way:

  1. Rename the .xlsx to .zip
  2. Unzip to a temp-folder
  3. Make the necessary changes
  4. Zip the files
  5. 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.