Пример #1
0
        border_bt = make_table_cell_border_string(
            thick='0.80cm',
            color='white',
        )
        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)
Пример #2
0
if __name__ == "__main__":

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