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 structure with all its files and subdirectories, compress them into a zip file and set its extension to xlsx. I use GDataXML parser/writer for creating all the necessary xml files. However, the file I get can't be opened as xlsx file. Even if I rip all the data from a valid xlsx file, create all the xml files manually by copying data from the original xml files and compress them manually, I can't recreate a valid xlsx file.
The questions are:
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