Esempio n. 1
0
    def insert(self):
        if DEBUG:
            print('Adding number...')

        table = self.cell_object.cell.add_table(rows=1, cols=1)

        if DEBUG:
            table.style = 'Table Grid'

        # add background color
        background_color = self.section.layout.get('style', {}).get(
            'backgroundColor', '')[1:]

        # Add the main number
        inner_cell = table.cell(0, 0)
        style_cell(inner_cell, color_hex=background_color)
        main_number = CellObject(inner_cell)

        sign = self.section.layout.get('sign', '')
        sign = '' if sign is None else sign
        insert_text(main_number,
                    str(self.section.contents) + sign, self.style['main'])

        main_number.add_paragraph(add_run=True)
        insert_text(main_number, str(self.section.extra['title']),
                    self.style['title'])
Esempio n. 2
0
def test_cell_object_add_paragraph():
    d = Document()
    table = d.add_table(1, 1)
    cell = table.cell(0, 0)
    co = CellObject(cell)
    co.run.text = 'old'

    assert len(d.element.xpath("//w:t[text()='old']")) == 1
    assert len(d.element.xpath("//w:t[text()='new']")) == 0

    co.add_paragraph()
    co.run.text = 'new'

    assert len(d.element.xpath("//w:t[text()='old']")) == 1
    assert len(d.element.xpath("//w:t[text()='new']")) == 1

    # Here we check it acctually came after
    check_order = d.element.xpath(
        '//w:p//w:t[text()="new"]/preceding::w:p//w:t[text()="old"]')
    assert check_order[0].text == 'old'
Esempio n. 3
0
    def insert(self):
        if DEBUG:
            print('Adding number...')

        table = self.cell_object.cell.add_table(rows=1, cols=1)

        if DEBUG:
            table.style = 'Table Grid'

        # Add the main number
        inner_cell = table.cell(0, 0)
        style_cell(inner_cell)
        main_number = CellObject(inner_cell)

        insert_text(main_number, str(self.section.contents),
                    self.style['main'])

        main_number.add_paragraph(add_run=True)
        insert_text(main_number, str(self.section.extra['title']),
                    self.style['title'])
Esempio n. 4
0
def test_cell_object_get_last_paragraph():
    d = Document()
    table = d.add_table(1, 1)
    cell = table.cell(0, 0)
    co = CellObject(cell)
    co.run.text = 'old'
    p = co.add_paragraph()
    co.run.text = 'new'

    last_p = co.get_last_paragraph()
    last_p.text = 'newnew'
    assert p.text == 'newnew'
    assert co.paragraph.text == 'newnew'