body.append(paragraph)

paragraph = Paragraph(style="line")
body.append(paragraph)

paragraph = Paragraph(style="smallserif")
paragraph.append_plain_text(text_2)
body.append(paragraph)

paragraph = Paragraph(style="line")
body.append(paragraph)

paragraph = Paragraph(style="description")
paragraph.append_plain_text(text_3)

# span offset become complex after inserting <CR> and <TAB> in a text
paragraph.set_span("bolder", offset=5, length=6)  # find TEXT position 5 : 6
paragraph.set_span("bolder", offset=18, length=4)  # find TEXT position 18 : 4
paragraph.set_span("bolder", offset=49)  # find TEXT position 18 to the end
# of the text bloc
paragraph.set_span("bolder",
                   regex="Praes\w+\s\w+")  # regex: Praes. + next word

body.append(paragraph)

if not os.path.exists("test_output"):
    os.mkdir("test_output")
output = os.path.join("test_output", "my_styled_plain_text_document.odt")

document.save(target=output, pretty=True)
Ejemplo n.º 2
0
# A paragraph with a highlighted word

# The style
style = Style(
    "text", "style2", parent="Standard", area="text", background_color=rgb2hex("yellow")
)
document.insert_style(style)

# The paragraph
text = (
    "The office document file format OpenDocument Format (ODF) "
    "is an ISO standard ISO 26300 used by many applications."
)
paragraph = Paragraph(text, "Standard")
paragraph.set_span("style2", regex="ISO standard")
body.append(paragraph)

# 4- A variable
# -------------

# A variable "spam" with the value 42
variable_set = VarSet("spam", 42)
value_type = variable_set.get_attribute("office:value-type")
variable_decl = VarDecl("spam", value_type)

# Insert
heading = Header(1, text="A variable")
body.append(heading)

decl = body.get_variable_decls()
Ejemplo n.º 3
0
# A paragraph with a highlighted word

# The style
style = Style('text',
              "style2",
              parent="Standard",
              area='text',
              background_color=rgb2hex('yellow'))
document.insert_style(style)

# The paragraph
text = ('The office document file format OpenDocument Format (ODF) '
        'is an ISO standard ISO 26300 used by many applications.')
paragraph = Paragraph(text, "Standard")
paragraph.set_span('style2', regex='ISO standard')
body.append(paragraph)

# 4- A variable
# -------------

# A variable "spam" with the value 42
variable_set = VarSet('spam', 42)
value_type = variable_set.get_attribute('office:value-type')
variable_decl = VarDecl('spam', value_type)

# Insert
heading = Header(1, text='A variable')
body.append(heading)

decl = body.get_variable_decls()