Exemple #1
0
        frame.append(image)
        paragraph.append(frame)
        body.append(paragraph)

        # And store the data
        container = document.container
        with open(path, 'rb') as f:
            content = f.read()
        container.set_part(internal_name, content)
    elif mimetype in ('text/csv', 'text/comma-separated-values'):
        table = Table("table %d" % numero, style="Standard")
        csv = reader(open(path))
        for line in csv:
            size = len(line)
            row = Row()
            for value in line:
                cell = Cell(value)
                row.append_cell(cell)
            table.append_row(row)
        for i in range(size):
            column = Column(style="Standard")
            table.insert(column, FIRST_CHILD)
        body.append(table)
    else:
        paragraph = Paragraph("Not image / csv", style="Standard")
        body.append(paragraph)

if not exists('test_output'):
    mkdir('test_output')
document.save('test_output/use_case1.odt', pretty=True)
Exemple #2
0
        border_rl = make_table_cell_border_string(thick='0.20cm',
                                                  color='white')
        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)
Exemple #3
0
    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)
        #row.set_value(2, quantity)
        p = prod.price * quantity
        cell = Cell()
        cell.set_value(p, text="%.2f €" % p, currency="EUR", cell_type="float")
        row.set_cell(3, cell)
        row_number += 1
        table.set_row(row_number, row)