Correct way to create this document (Not Unity)

Updated on June 28, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on June 28, 2017

Hello everyone, I’ve been asked to create this program which auto fills a open office calc document (basically a free version of excel). In the program you type in some text in some text boxes and when you click save it should save the document with the content of the text boxes inside it. I did some research and I found how to input the text in the document. What you have to do is:


1. Change the .ods (the open office document file extension) in to a .zip.


2. Open the zip file.


3. Inside that file open up content.xml.


4. Input your data.


I’ve managed to do that, but I think I did it in a very messy and bad way. This is how I did it:

    1. I created the .zip file and extracted it. I named the extracted folder “DocOrigin”. (This is done manually, not in code)


    1. (This is in code) I copy the folder using
      and name the new folder “Doc”.


    1. I open the “Doc” folder, open content.xml and Input my data.


    1. I then zip “Doc” using 
      and name the new zipped file “ZipDoc”.


    1. I change the file extension of “ZipDoc” to .ods with this line:
      File.Move("ZipDoc", Path.ChangeExtension("ZipDoc", ".ods"))


    1. I delete the leftover folder “Doc” with

I feel like there should be a way to do this without all the zipping copying and deleting. Also whenever you extract a zip file to folder and then zip it again and change the file extension to .ods Open Office says that the file has been corrupted(It still opens and the data that I input is fine and correct). My questions are: Is there a way to edit a .zip file through code without unzipping it? How would you save the file and Input the data? Thanks for the help 🙂

  • Liked by