예제 #1
0
from odfdo import Document, Table

document = Document('spreadsheet')
body = document.body

table = Table("Empty Table")
table.set_value('A1', "Hello World")
body.append(table)
from odfdo import Document, Table

document = Document("spreadsheet")
body = document.body

table = Table("Empty Table")
table.set_value("A1", "Hello World")
body.append(table)
#!/usr/bin/env python
"""
Create a spreadsheet with two tables, using some named ranges.
"""
import os

from odfdo import Document, Table

if __name__ == "__main__":
    document = Document('spreadsheet')
    body = document.body
    table = Table("First Table")
    body.append(table)
    # populate the table :
    for i in range(10):
        table.set_value((1, i), (i + 1)**2)
    table.set_value("A11", "Total:")

    # lets define a named range for the 10 values :
    crange = "B1:B10"
    name = "squares_values"
    table_name = table.name
    table.set_named_range(name, crange, table_name)

    # we can define a single cell range, using notation "B11" or (1, 10) :
    table.set_named_range('total', (1, 10), table_name)

    # get named range values :
    values = table.get_named_range('squares_values').get_values(flat=True)

    # set named range value :
예제 #4
0
    # A table contains rows, we can append some more.
    for r in range(2):
        table.append_row()
    print("rows in the table (3+2):", len(table.get_rows()))

    #  A row contains cells
    for row in table.get_rows():
        print("row, nb of cells ", row.y, len(row.get_cells()))

    last_row = table.get_row(-1)
    print("nb of cells of the last row:", len(last_row.get_cells()))

    # cell can have different kind of values
    for r in range(3):
        for c in range(10):
            table.set_value((c, r), "cell %s %s" % (c, r))
    for r in range(3, 5):
        for c in range(10):
            table.set_value((c, r), c * 100 + r)

    # Before saving the document,  we can strip the unused colums:
    print("table size:", table.size)
    table.rstrip()
    print("table size after strip:", table.size)
    print("nb of cells of the last row:", len(table.get_row(-1).get_cells()))
    print("Content of the table:")
    print(table.to_csv())

    if not os.path.exists('test_output'):
        os.mkdir('test_output')
예제 #5
0
#!/usr/bin/env python
"""
Create a spreadsheet with two tables, using some named ranges.
"""
import os

from odfdo import Document, Table

if __name__ == "__main__":
    document = Document("spreadsheet")
    body = document.body
    table = Table("First Table")
    body.append(table)
    # populate the table :
    for i in range(10):
        table.set_value((1, i), (i + 1)**2)
    table.set_value("A11", "Total:")

    # lets define a named range for the 10 values :
    crange = "B1:B10"
    name = "squares_values"
    table_name = table.name
    table.set_named_range(name, crange, table_name)

    # we can define a single cell range, using notation "B11" or (1, 10) :
    table.set_named_range("total", (1, 10), table_name)

    # get named range values :
    values = table.get_named_range("squares_values").get_values(flat=True)

    # set named range value :