def test_row_negative_index(self):
        row = DDERow()
        cell = DDECell(1)
        row.add_cell(cell)

        dde_table = DDETable()
        dde_table.add_row(row)

        self.assertIsNone(dde_table.row(-1))
    def test_row(self):
        row = DDERow()
        cell = DDECell(1)
        row.add_cell(cell)

        dde_table = DDETable()
        dde_table.add_row(row)

        self.assertEqual(dde_table.row(0).cell(0).value, 1)
    def test_row_bigger_index(self):
        row = DDERow()
        cell = DDECell(1)
        row.add_cell(cell)

        dde_table = DDETable()
        dde_table.add_row(row)

        self.assertIsNone(dde_table.row(10))
예제 #4
0
    def _get_tables_information(self, doc):
        tables = []
        table_counter = 0
        for table in doc.tables:
            table_counter += 1
            has_check_boxes = False

            dde_table = DDETable()
            dde_table.index = table_counter

            # print('{:_<80}'.format('_'))
            rows = table.rows
            row_counter = 0
            for row in rows:
                # print('{:_<50}'.format('_'))

                dde_row = DDERow()
                dde_row.index = row_counter

                row_counter += 1
                col_counter = 0

                # Select regular columns
                tcElements = etree.ElementBase.xpath(
                    row._element, './/w:tc', namespaces=row._element.nsmap)
                if tcElements:
                    for tcElem in tcElements:
                        val = self._get_tc_value(tcElem)

                        if val is None:
                            continue

                        dde_cell = DDECell()
                        dde_cell.row_index = row_counter
                        dde_cell.column_index = col_counter
                        dde_cell.cell_type = 'text'
                        dde_cell.value = val

                        dde_row.add_cell(dde_cell)
                        # print('[{:d},{:d}] <{:s}>'.format(dde_cell.row_index, dde_cell.column_index, dde_cell.value))
                        col_counter += 1

                # Find checkboxes
                sdtElements = row._element.xpath('.//w:sdt')
                if sdtElements:
                    for sdt in sdtElements:
                        col_counter += 1
                        val = self._get_chbox_value(sdt)

                        dde_cell = DDECell()
                        dde_cell.row_index = row_counter
                        dde_cell.column_index = col_counter
                        dde_cell.cell_type = 'checkbox'
                        dde_cell.value = val

                        dde_row.add_cell(dde_cell)
                        has_check_boxes = True
                        # print('[{:d},{:d}] <{:s}>'.format(dde_cell.row_index, dde_cell.column_index, dde_cell.value))

                dde_table.add_row(dde_row)

            if has_check_boxes:
                dde_table.name = dde_table.row(0).cell(1).value
                tables.append(dde_table)

        return tables