Skip to main content

Posts

Showing posts with the label unzip

Bash and Python scripts to unzip and modify an OpenOffice odt document

.odt files are actually containers (you can see one using unzip -l document.odt ). Within the container, content is in the content.xml file. Script info source Heres what Ive figured out about opening, modifying, and saving the content of an .odt file: To open the container for editing: # bash $unzip path/container.odt content.xml $unzip path/container.odt content.xml -d working/dir/path/ # -d places content.xml in a different directory. # Creates a content.xml file where you want it. # python >>>import zipfile >>>odt_file = zipfile.ZipFile(path/to/file.odt,a) >>> # Options are read only, write only, and append to existing >>>raw_xml = odt_file.read(content.xml) >>> # Reads content.xml in as a string, doesnt place a file. Modify the content.xml file by hand, or using a script, or using Python. >>> # Tip for using python: ElementTree is good at XML, and it can parse a file, but it cannot parse a string! >>> # So heres h...