Beispiel #1
0
    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:
            found.append(word)
    print("list of words of frequency 15:", ", ".join(found))
Beispiel #2
0
        style = create_table_cell_style(
            color='grey',
            background_color=cell_value,
            border_right=border_rl,
            border_left=border_rl,
            border_bottom=border_bt,
            border_top=border_bt,
        )
        name = document.insert_style(style=style, automatic=True)
        cell = Cell(value=rgb2hex(cell_value), style=name)
        row.append_cell(cell)
    table.append_row(row)

    row_style = Style('table-row', height='1.80cm')
    name_style_row = document.insert_style(style=row_style, automatic=True)
    for row in table.get_rows():
        row.style = name_style_row
        table.set_row(row.y, row)

    col_style = Style('table-column', width='3.6cm')
    name = document.insert_style(style=col_style, automatic=True)
    for column in table.get_columns():
        column.style = col_style
        table.set_column(column.x, column)

body.append(table)

if not exists('test_output'):
    mkdir('test_output')
document.save(join('test_output', 'use_case3.ods'), pretty=True)
Beispiel #3
0
    # creating an empty spreadsheet document:
    document = Document('spreadsheet')

    # Each sheet of a spreadsheet is a table:
    # setting drom the beginning width (columns) and height (rows)
    # is not mandatory, but a good practice, since odfdo don't check
    # actual existence of cells
    body = document.body
    table = Table("First Table", width=20, height=3)
    body.append(table)

    # 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)