Skip to content
Philipp Hirsch edited this page Feb 9, 2014 · 6 revisions

Use of the ODF-Class

The first example shows how to create a new document. $type can be text, spreadsheet or an other document type.

   $document = new ODF();
   $document->create($type);

To save the document, you can use the following code. $path is used as the path where the document will be saved.

  $document->save($path);

If you want to extend an existing document, you can load it with this code.

  $document = new ODF();
  $document->open($path);

Now you can add elements to your document. ODFphp provides some shortcuts to do this.

Content Body

After initializing your document, you can call:

  $content = ODF_Text::getContentBody($document);

or, if you are editing an spreadsheet:

  $content = ODF_Spreadsheet::getContentBody($document);

$content now contains the DOMElement and most of the shortcuts create DOMElements, that can be added to the content body.

  $content->appendChild($element);

Further reading

See the following pages for detailed information about shortcuts:

Clone this wiki locally