pythonodtopendocumentodfpy

Add Section to OpenDocument Text file with ODFpy


I am using Python2.7 and ODFpy to write an OpenDocument Text (ODT) file. Is there a way using the existing ODFpy API to add sections (a la Format->Sections...) to the document? Is there a way to import them from another document and then populate them, or to otherwise fetch the styling from another document?


Solution

  • A section can be added to a document by a method something like this:

    from odf import text as odftext
    from odf import opendocument
    document = opendocument.OpenDocument()
    document.text.addElement(odftext.Section(name="section1"))