Use ODFDOM to create text, spreadsheets, and presentation graphics documents
First, let's briefly describe the ODF document structure. The ODF document is saved in a ZIP-compressed package that contains Content.xml, Style.xml, and several other documents.
Content.xml is used to save document content, Style.xml to save document style information. The Content.xml file also contains some style information that can be used to automatically create default values, such as fonts and colors.
In general, the operation of an ODF document is divided into four steps:
Load an existing ODF document or create an ODF document.
Inserts content into the ODF document.
Sets the style for different parts of the information.
Save the document.
ODFDOM now provides APIs that allow you to easily complete these four-step operations.
Create a text file
In this section, we will demonstrate a simple use case: Reading an XML file and outputting it to the ODF document.
As a text file, the content.xml level is as follows (see Listing 1):
The first element is <office:body>, which is a child element of the document's root directory.
The next level is the <office:text> element, which represents all the document elements to be saved in the output document.
The <office:automatic-styles> before <office:body> is another child element of the document root that holds various style information for the element.
Listing 1. Content.xml-level structure of text files
<office:document- content>
<office:automatic-style/>
<office:body>
<office:text/>
</office:body>
</ office:document-content>