def test_append_column(self):
     table = self.table.clone()
     table.append_column(odf_create_column())
     self.assertEqual(table.get_table_width(), 8)
     self.assertEqual(table.get_row(0).get_row_width(),  7)
     # The column must be inserted between the columns and the rows
     self.assert_(type(table.get_children()[-1]) is not odf_column)
Beispiel #2
0
 def test_append_column(self):
     table = self.table.clone()
     table.append_column(odf_create_column())
     self.assertEqual(table.get_columns_width(), 8)
     self.assertEqual(table.get_row(0).get_width(), 7)
     # The column must be inserted between the columns and the rows
     self.assert_(type(table.get_children()[-1]) is not odf_column)
Beispiel #3
0
 def test_all(self):
     column =  odf_create_column(style=u"co1",
             default_cell_style="Standard", repeated=3)
     expected = ('<table:table-column '
                   'table:default-cell-style-name="Standard" '
                   'table:number-columns-repeated="3" '
                   'table:style-name="co1"/>')
     self.assertEqual(column.serialize(), expected)
Beispiel #4
0
 def test_all(self):
     column = odf_create_column(style=u"co1",
                                default_cell_style="Standard",
                                repeated=3)
     expected = ('<table:table-column '
                 'table:default-cell-style-name="Standard" '
                 'table:number-columns-repeated="3" '
                 'table:style-name="co1"/>')
     self.assertEqual(column.serialize(), expected)
def convert_table(node, context):
    styles = context["styles"]
    cell_style = styles.get('cell_style')
    if cell_style is None:
        cell_style = odf_create_style('table-cell', u"odf_table.A1",
                padding=u"0.049cm", border=u"0.002cm solid #000000")
        context['doc'].insert_style(cell_style, automatic=True)
        styles['cell_style'] = cell_style

    for tgroup in node:
        if tgroup.tagname != "tgroup":
            warn('node "%s" not supported in table' % tgroup.tagname)
            continue
        columns_number = 0
        odf_table = None
        for child in tgroup:
            tagname = child.tagname
            if tagname == "thead" or tagname == "tbody":
                # Create a new table with the info columns_number
                if odf_table is None:
                    context["tables_number"] += 1
                    # TODO Make it possible directly with odf_create_table
                    odf_table = odf_create_table(name="table%d" %
                                                 context["tables_number"])
                    columns = odf_create_column(repeated=columns_number)
                    odf_table.append_element(columns)
                # Convert!
                if tagname == "thead":
                    header = odf_create_header_rows()
                    odf_table.append_element(header)

                    _convert_table_rows(header, child, context,
                            cell_style=cell_style.get_style_name())
                else:
                    _convert_table_rows(odf_table, child, context,
                            cell_style=cell_style.get_style_name())
            elif tagname == "colspec":
                columns_number += 1
            else:
                warn('node "%s" not supported in tgroup' % child.tagname)
                continue

        context["top"].append_element(odf_table)
 def test_default(self):
     column = odf_create_column()
     expected = '<table:table-column/>'
     self.assertEqual(column.serialize(), expected)
 def test_insert_column(self):
     table = self.table.clone()
     table.insert_column(3, odf_create_column())
     self.assertEqual(table.get_table_width(), 8)
     self.assertEqual(table.get_row(0).get_row_width(), 8)
        frame.append_element(image)
        paragraph.append_element(frame)
        body.append_element(paragraph)

        # And store the data
        container = document.container
        container.set_part(internal_name,
                           samples.open(filename).read())
    elif isinstance(handler, CSVFile):
        table = odf_create_table(u"table %d" % numero, style=u"Standard")
        for csv_row in handler.get_rows():
            size = len(csv_row)
            row = odf_create_row()
            for value in csv_row:
                cell = odf_create_cell(value)
                row.append_element(cell)
            table.append_element(row)
        for i in xrange(size):
            column = odf_create_column(style=u"Standard")
            table.insert_element(column, FIRST_CHILD)
        body.append_element(table)
    else:
        paragraph = odf_create_paragraph(u"Not image / csv",
                style=u"Standard")
        body.append_element(paragraph)

vfs.make_folder('test_output')
document.save('test_output/use_case1.odt', pretty=True)


Beispiel #9
0
                                 str(height / 72.0) + 'in')
        image = odf_create_image(internal_name)
        frame.append(image)
        paragraph.append(frame)
        body.append(paragraph)

        # And store the data
        container = document.container
        container.set_part(internal_name, open(path).read())
    elif mimetype in ('text/csv', 'text/comma-separated-values'):
        table = odf_create_table(u"table %d" % numero, style=u"Standard")
        csv = reader(open(path))
        for line in csv:
            size = len(line)
            row = odf_create_row()
            for value in line:
                cell = odf_create_cell(value)
                row.append(cell)
            table.append(row)
        for i in xrange(size):
            column = odf_create_column(style=u"Standard")
            table.insert(column, FIRST_CHILD)
        body.append(table)
    else:
        paragraph = odf_create_paragraph(u"Not image / csv", style=u"Standard")
        body.append(paragraph)

if not exists('test_output'):
    mkdir('test_output')
document.save('test_output/use_case1.odt', pretty=True)
 def test_all(self):
     column =  odf_create_column(style=u"co1",
             default_cell_style="Standard", repeated=3)
     expected = ('<table:table-column table:style-name="co1" '
                   'table:default-cell-style-name="A Style"/>'
                   'table:number-columns-repeated="3"/>')
Beispiel #11
0
 def setUp(self):
     self.column = odf_create_column(default_cell_style=u"ce1",
                                     repeated=7,
                                     style=u"co1")
Beispiel #12
0
 def test_style(self):
     column = odf_create_column(style=u"A Style")
     expected = '<table:table-column table:style-name="A Style"/>'
     self.assertEqual(column.serialize(), expected)
Beispiel #13
0
 def test_default_cell_style(self):
     column = odf_create_column(default_cell_style=u"A Style")
     expected = ('<table:table-column '
                 'table:default-cell-style-name="A Style"/>')
     self.assertEqual(column.serialize(), expected)
Beispiel #14
0
 def test_default(self):
     column = odf_create_column()
     expected = '<table:table-column/>'
     self.assertEqual(column.serialize(), expected)
 def test_default_cell_style(self):
     column = odf_create_column(default_cell_style=u"A Style")
     expected = ('<table:table-column '
                   'table:default-cell-style-name="A Style"/>')
     self.assertEqual(column.serialize(), expected)
 def test_style(self):
     column = odf_create_column(style=u"A Style")
     expected = '<table:table-column table:style-name="A Style"/>'
     self.assertEqual(column.serialize(), expected)
Beispiel #17
0
    # Could be pushed to another position
    table.set_row(0, first_row)

    # Accessing cells from the table
    second_cell = table.get_cell("B1")

    # Cells are XML elements
    second_cell.clear()
    second_cell.append(odf_create_paragraph(u"World"))

    # Modified cells must be pushed back
    # Could be pushed to another position
    table.set_cell((1, 0), second_cell)

    # Append a column (and adjust the table size)
    table.append_column(odf_create_column())

    # Add an image in the document
    image_uri = document.add_file('../.static/banner-lpod_en.png')

    # Images are in frame
    frame = odf_create_image_frame(image_uri, size=('11.87cm', '1.75cm'),
            position=('0cm', '0cm'))

    # Displaying an image in a cell is tricky: the document type must be
    # given or the table attached to the document
    table.set_cell_image((-1, 0), frame, type=document.get_type())

    # The table is a regular element
    body.append(table)
 def setUp(self):
     self.column = odf_create_column(default_cell_style=u"ce1",
             repeated=7, style=u"co1")
Beispiel #19
0
 def test_insert_column(self):
     table = self.table.clone()
     table.insert_column(3, odf_create_column())
     self.assertEqual(table.get_width(), 8)
     self.assertEqual(table.get_row(0).get_width(), 8)