jdum / odfdo

python library for OpenDocument format (ODF)
Apache License 2.0
58 stars 11 forks source link

Use style to have a section with 2 columns #22

Closed papoteur-mga closed 1 year ago

papoteur-mga commented 1 year ago

I try to build a document with a section inside it to have two columns in this section. I didn't find a way to specify that the created section has 2 columns. Here my attempt:


title = "My great document"
writer = Document('text')
writer.body.append(Paragraph(title))

writer.body.append(Element.from_tag("text:soft-page-break"))
writer.body.append(Header(1, "New page"))
writer.body.append(Paragraph("A first Paragraph"))

section_style = Style(name="Twocol", 
                              family="section",
                              display_name="Two columns"
                              )
section_style.set_properties(properties={"fo:column-count":"2"}, area="columns")
section = Section(name="Section1", style = section_style)

section.append(Header(2,"Something:"))
section.append(Paragraph("Blabla"))
section.append(Header(2,"Something else:"))
section.append(Paragraph("Blabla"))
section.append(Header(2,"Something else:"))
section.append(Paragraph("Blabla"))
writer.body.append(section)

writer.body.append(Header(1, "End part"))
writer.body.append(Paragraph("A last Paragraph"))        

#section_style =  Element.from_tag(
    #(   '<style:style style:name="Sect1" style:family="section"><style:section-properties style:editable="false"><style:columns fo:column-count="2" fo:column-gap="0.497cm"><style:column style:rel-width="32767*" fo:start-indent="0cm" fo:end-indent="0.248cm"/><style:column style:rel-width="32768*" fo:start-indent="0.248cm" fo:end-indent="0cm"/></style:columns></style:section-properties></style:style>'
        #)
    #)

writer.save("mydoc.odt")

The document is created with the section, but the section doesn't have 2 columns. I tried also to add a break page I have also tried to define the style from a tag (see what is commented), without success. I tried also to add a break page after the title, without more success. What have I missed?

jdum commented 1 year ago

Hi, I managed to make it work this way:

papoteur-mga commented 1 year ago

@jdum Thanks, this works, indeed. I missed (at least) the insertion of the style and the reference with its name.