Example #1
0
# 2- Your environment (=> a table)
# --------------------------------
heading = Header(1, text="Your environment")
body.append(heading)

data = []

# lpOD Version
data.append(["odfdo library version", __version__])

# Python version
data.append(["Python version", "%d.%d.%d" % version_info[:3]])

# Creation / Insertion
table = Table("table1", width=2, height=2, style="Standard")
table.set_values(data)
body.append(table)

# 3- Description (=> footnote & => highlight)
# -------------------------------------------

heading = Header(1, text="Description")
body.append(heading)

# A paragraph with a note
text = "The odfdo project is made to generate easily OpenDocuments."
paragraph = Paragraph(text, style="Standard")
paragraph.insert_note(
    after="odfdo project", note_id="note1", citation="1", body="http://xxxxxxxxxxxx/"
)
body.append(paragraph)
Example #2
0
    sorted = [(value, key) for key, value in frequences.items()]
    sorted.sort()
    sorted.reverse()

    # one solution :

    # for value, key in sorted:
    #    row = Row()
    #    row.set_value(0, key)
    #    row.set_value(1, value) # Cell type is guessed.
    #    table.append_row(row)

    # another solution :
    sorted = [(k, v) for (v, k) in sorted]
    table.set_values(sorted)

    print("rows in the table :", len(table.get_rows()))

    # frequency of word:
    regex_query = "^the"
    print("Words corresponding to the regex:", regex_query)
    result = table.get_rows(content=regex_query)
    for row in result:
        print("word: %-20s  occurences: %s" %
              (row.get_value(0), row.get_value(1)))

    # list of words of frequecy = 15
    found = []
    for word, freq in table.iter_values():
        if freq == 15:
    table2.set_value('A2', "range:")
    table2.set_value('B2', str(named_range1.crange))
    table2.set_value('A3', "from table:")
    table2.set_value('B3', named_range1.table_name)
    table2.set_value('A4', "content:")
    table2.set_value('B4', named_range1.get_value())

    named_range2 = table2.get_named_range('squares_values')
    table2.set_value('D1', "name:")
    table2.set_value('E1', named_range2.name)
    table2.set_value('D2', "range:")
    table2.set_value('E2', str(named_range2.crange))
    table2.set_value('D3', "from table:")
    table2.set_value('E3', named_range2.table_name)
    table2.set_value('D4', "content:")
    # using "E4:4" notaion is a little hack for the area starting at E4 on row 4
    table2.set_values(values=[named_range2.get_values(flat=True)],
                      coord='E4:4')

    print("Content of the table1:")
    print(table.name)
    print(table.to_csv())
    print(table2.name)
    print(table2.to_csv())

    # of course named ranges are stored in the document :
    if not os.path.exists('test_output'):
        os.mkdir('test_output')
    output = os.path.join('test_output', "my_spreadsheet_with_named_range.ods")
    document.save(target=output, pretty=True)