def find_table_for(self, sheet, tables, name, type): for table in tables: rowlo = table['rowlo'] rowhi = table['rowhi'] collo = table['collo'] colhi = table['colhi'] if type is None or type == 'col': cnames = [v if type(v) is not float else self._format_date(v)\ for v in (sheet.cell_value(rowx=rowlo,colx=ci) \ for ci in range(collo, colhi + 1))] if best_match(cnames, name) is not None: return table if type is None or type == 'row': rnames = [v if type(v) is not float else self._format_date(v)\ for v in (sheet.cell_value(rowx=ri,colx=collo) \ for ci in range(collo, colhi + 1))] if best_match(rnames, name) is not None: return table return None
def _get_row_no(self, sheet, table, row_name): header_row = table['rowlo'] header_col = table['collo'] if row_name is None or row_name == '': return -1 rowlo = header_row + 1 rowhi = table['rowhi'] rownames = [v if type(v) is not float else self._format_date(v) \ for v in (sheet.cell_value(rowx=ri,colx=header_col) \ for ri in range(rowlo, rowhi + 1))] match = best_match(rownames, row_name) return rowlo + rownames.index(match) if match is not None else -1
def _get_col_no(self, sheet, table, col_name): header_row = table['rowlo'] header_col = table['collo'] if col_name is None or col_name == '': return colno collo = header_col + 1 colhi = table['colhi'] colnames = [v if type(v) is not float else self._format_date(v) \ for v in (sheet.cell_value(rowx=header_row,colx=ci) \ for ci in range(collo, colhi + 1))] match = best_match(colnames, col_name) return collo + colnames.index(match) if match is not None else -1
def find_table_by_name(self, tables, name): match = best_match(tables.keys(), name) return tables[match] if match is not None and match in tables else None
def get_sheet(self, name): match = best_match(self.workbook.sheet_names(), name) return self.workbook.sheet_by_name(match) \ if match is not None else None