eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
308 stars 63 forks source link

Automaticstyle not added into content xml #113

Open Sefran007 opened 2 years ago

Sefran007 commented 2 years ago

from odf.opendocument import OpenDocumentText from odf.style import Style, TextProperties, ParagraphProperties

document_test = OpenDocumentText()

paragraph_style = Style(name='Test', family='paragraph') paragraph_style.addElement(ParagraphProperties(numberlines='false', linenumber='0')) paragraph_style.addElement(TextProperties(fontsize='24pt', fontweight='bold')) document_test.automaticstyles.addElement(paragraph_style)

document_test.contentxml()

Return : b'\<?xml …>\\\\</office:body>\</office:document-content>'

Missing xml syntax of automatic style

I'm test them on Ubuntu 21.04 and Manjaro 21.2.1 with Python 3.9.5 and 3.10.1

kivdev commented 2 years ago

Sorry for using google translate. You have two options for using the library without changing it:

  1. Use names without separators.
  2. Do as I do:
    
    from odf.attrconverters import make_NCName
    from odf.style import Style
    from odf.table import Table

display_name = "New Style" name = make_NCName(display_name) Style(name=display_name) ...

t = Table(stylename=name)