Example #1
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)
Example #2
0
    body.append(product_list)
    for product in catalog:
        item = ListItem("%-10s, price: %.2f €" % (product.name, product.price))
        product_list.append(item)

    title12 = Header(2, "Your command")
    body.append(title12)

    command = {0: 1, 1: 12, 2: 3, 4: 5}

    # A table in the text document :
    table = Table("Table")
    body.append(table)
    row = Row()
    row.set_values(["Product", "Price", "Quantity", "Amount"])
    table.set_row("A1", row)
    # or: table.set_row(0, row)
    row_number = 0
    for item, quantity in command.items():
        prod = catalog[item]
        row = Row()
        row.set_value("A", prod.name)
        #or : row.set_value(0, prod.name)
        cell = Cell()
        cell.set_value(prod.price,
                       text="%.2f €" % prod.price,
                       currency="EUR",
                       cell_type="float")
        row.set_cell("B", cell)
        #or : row.set_cell(1, cell)
        row.set_value("C", quantity)