Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ TODO
- Improve integration with pyopenxl for reading and writing files `example of
problem space <https://stackoverflow.com/questions/40248564/pre-calculate-excel-formulas-when-exporting-data-with-python>`_


- Support named constants

Supported Functions
-------------------
Expand Down
12 changes: 12 additions & 0 deletions tests/xlfunctions/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def test_VLOOOKUP_with_unknown_lookup_value(self):
self.assertIsInstance(
lookup.VLOOKUP(102, range1, 2, False), xlerrors.NaExcelError)

def test_VLOOOKUP_low_lookup_id(self):
# Excel Doc example.
range1 = func_xltypes.Array([
[101, 'Davis', 'Sara'],
[102, 'Fortana', 'Olivier'],
[103, 'Leal', 'Karina'],
[104, 'Patten', 'Michael'],
[105, 'Burke', 'Brian'],
[106, 'Sousa', 'Luis'],
])
self.assertEqual(lookup.VLOOKUP(102, range1, 1, False), 'Fortana')

def test_MATCH(self):
range1 = [25, 28, 40, 41]
self.assertEqual(lookup.MATCH(39, range1), 2)
Expand Down
2 changes: 1 addition & 1 deletion xlcalculator/ast_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_cells(self):

@property
def address(self):
return self.tvalue
return self.tvalue.replace("$","")

def full_address(self, context):
addr = self.address
Expand Down
9 changes: 5 additions & 4 deletions xlcalculator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ def cells(self):
@property
def ranges(self):
return self.evaluator.model.ranges

@lru_cache(maxsize=None)

def eval_cell(self, addr):
# Check for a cycle.
if addr in self.seen:
raise RuntimeError(
f'Cycle detected for {addr}:\n- ' + '\n- '.join(self.seen))

self.seen.append(addr)

return self.evaluator.evaluate(addr, None)
val = self.evaluator.evaluate(addr, None)
self.seen.remove(addr)
return val


class Evaluator:
Expand Down
5 changes: 4 additions & 1 deletion xlcalculator/xlfunctions/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def VLOOKUP(
raise xlerrors.NaExcelError(
'`lookup_value` not in first column of `table_array`.')

return table_array.loc[lookup_value].values[0]
if col_index_num <= 1:
col_index_num = 2

return table_array.loc[lookup_value].values[col_index_num-2]


@xl.register()
Expand Down