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))
def test_row_count(self): row = DDERow() cell = DDECell(1) row.add_cell(cell) dde_table = DDETable() dde_table.add_row(row) self.assertEqual(dde_table.row_count(), 1)
def test_add_row(self): row = DDERow() cell = DDECell(1) row.add_cell(cell) dde_table = DDETable() dde_table.add_row(row) self.assertEqual(len(dde_table.rows), 1)
def test_property_rows(self): row = DDERow() cell = DDECell(1) row.add_cell(cell) rows = [row] dde_table = DDETable() dde_table.rows = rows self.assertEqual(len(dde_table.rows), 1)
def test_property_name(self): dde_table = DDETable() dde_table.name = 'name' self.assertEqual(dde_table.name, 'name')
def test_property_index(self): dde_table = DDETable() dde_table.index = 1 self.assertEqual(dde_table.index, 1)
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