def test_address_cell_enum(ATestCell): assert ('B1', '', 2, 1, 'B1') == AddressCell('B1') assert ('sheet!B1', 'sheet', 2, 1, 'B1') == AddressCell('sheet!B1') assert ('A1', '', 1, 1, 'A1') == AddressCell('R1C1') assert ('sheet!A1', 'sheet', 1, 1, 'A1') == AddressCell('sheet!R1C1') cell = ATestCell('A', 1) assert ('B2', '', 2, 2, 'B2') == AddressCell.create('R[1]C[1]', cell=cell) assert ('sheet!B2', 'sheet', 2, 2, 'B2') == AddressCell.create('sheet!R[1]C[1]', cell=cell) with pytest.raises(ValueError): AddressCell('B1:C2') with pytest.raises(ValueError): AddressCell('sheet!B1:C2') with pytest.raises(ValueError): AddressCell('xyzzy')
def _formula_cells(self): """Iterate all cells and find cells with formulas""" if self._formula_cells_list is None: self._formula_cells_list = [ AddressCell.create(cell.coordinate, ws.title) for ws in self.excel.workbook for row in ws.iter_rows() for cell in row if isinstance(getattr(cell, 'value', None), str) and cell.value.startswith('=') ] return self._formula_cells_list
def test_address_cell_enum(): assert ('B1', '', 2, 1, 'B1') == AddressCell('B1') assert ('sheet!B1', 'sheet', 2, 1, 'B1') == AddressCell('sheet!B1') assert ('A1', '', 1, 1, 'A1') == AddressCell('R1C1') assert ('sheet!A1', 'sheet', 1, 1, 'A1') == AddressCell('sheet!R1C1') cell = ATestCell('A', 1) assert ('B2', '', 2, 2, 'B2') == AddressCell.create( 'R[1]C[1]', cell=cell) assert ('sheet!B2', 'sheet', 2, 2, 'B2') == AddressCell.create( 'sheet!R[1]C[1]', cell=cell) with pytest.raises(ValueError): AddressCell('B1:C2') with pytest.raises(ValueError): AddressCell('sheet!B1:C2') with pytest.raises(ValueError): AddressCell('xyzzy')
def formula_cells(self, sheet=None): """Iterate all cells and find cells with formulas""" if sheet is None: return list( it.chain.from_iterable( self.formula_cells(sheet.title) for sheet in self.excel.workbook)) if sheet not in self._formula_cells_dict: if sheet in self.excel.workbook: self._formula_cells_dict[sheet] = tuple( AddressCell.create(cell.coordinate, sheet) for row in self.excel.workbook[sheet].iter_rows() for cell in row if isinstance(getattr(cell, 'value', None), str) and cell.value.startswith('=')) else: self._formula_cells_dict[sheet] = tuple() return self._formula_cells_dict[sheet]
def formula_cells(self, sheet=None): """Iterate all cells and find cells with formulas""" if sheet is None: return list(it.chain.from_iterable( self.formula_cells(sheet.title) for sheet in self.excel.workbook)) if sheet not in self._formula_cells_dict: if sheet in self.excel.workbook: self._formula_cells_dict[sheet] = tuple( AddressCell.create(cell.coordinate, sheet) for row in self.excel.workbook[sheet].iter_rows() for cell in row if isinstance(getattr(cell, 'value', None), str) and cell.value.startswith('=') ) else: self._formula_cells_dict[sheet] = tuple() return self._formula_cells_dict[sheet]