I\'m trying to create an xlsx file programmatically on iOS. Since the internal data of xlsx files is basically stored in separate xml files, I tried to recreate xlsx structu
I was having issues and found that was zipping on the wrong folder level. You need to navigate into folder created when you unziped the xlsx and zip the actual files, not the container folder. Dummy me, shared my story, maybe it can help others save time...
In answer to your questions:
Example of the contents of an xlsx file:
unzip -l example.xlsx
Archive: example.xlsx
Length Date Time Name
-------- ---- ---- ----
769 10-15-14 09:23 xl/worksheets/sheet1.xml
550 10-15-14 09:22 xl/workbook.xml
201 10-15-14 09:22 xl/sharedStrings.xml
...
I regularly unzip XLSX files, make minor changes for testing and re-zip them without any issue.
Update: The important thing is to avoid zipping the parent directory. Here is an example using the zip
system utility on Linux or the OS X:
# Unzip an xlsx file into a directory.
unzip example.xlsx -d newdir
# Make some valid changes to the files.
cd newdir/
vi xl/worksheets/sheet1.xml
# Rezip the files *FROM* the unzipped directory.
# Note: you could also re-zip to the original file if required.
find . -type f | xargs zip ../newfile.xlsx
# Check the file looks okay.
cd ..
unzip -l newfile.xlsx
xdg-open newfile.xlsx
I was using WinZip 15.5 to rezip xlsx xml files. Different compression types produced different results.
Note: The original file size was 555KB.
Conclusion: Zip SuperFast is the only effective compression format.
If I decompress an xlsx file into a folder and then I recompress it again, the xlsx becomes corrupt / not recognized. In my case, the cause is that my zip tool is using the folder name as the first level for the relative path of each file inside the zip.
I have solved the problem by creating an empty zip file INSIDE the folder with the xlsx contents and then adding all the files and folders to it.
Actually, if you try to zip the folder itself, the file is not a valid xlsx. You should rather go inside the folder, select all the contents and then right-click & zip.