Skip to content

Commit

Permalink
closes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
PydPiper committed Feb 1, 2023
1 parent 563e616 commit ea1539f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pylightxl/pylightxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
from datetime import datetime, timedelta

EXCEL_STARTDATE = datetime(1899,12,30)

MAX_XL_ROWS = 1048576
MAX_XL_COLS = 16384

########################################################################################################
# SEC-02: PYTHON2 COMPATIBILITY
Expand Down Expand Up @@ -1846,8 +1847,18 @@ def range(self, address, formula=False, output='v'):

if ':' in address:
address_start, address_end = address.split(':')
row_start, col_start = utility_address2index(address_start)
row_end, col_end = utility_address2index(address_end)
# check for entire row/col address
if address_start.isnumeric() and address_end.isnumeric():
# 1:1 is row 1, 1:3 is rows 1-3
row_start, col_start = int(address_start), 1
row_end, col_end = int(address_end), MAX_XL_COLS
elif address_start.isalpha() and address_end.isalpha():
# A:A is col A, A:C is col A-C
row_start, col_start = 1, utility_columnletter2num(address_start)
row_end, col_end = MAX_XL_ROWS, utility_columnletter2num(address_end)
else:
row_start, col_start = utility_address2index(address_start)
row_end, col_end = utility_address2index(address_end)

# +1 to include the end
for n_row in range(row_start, row_end + 1):
Expand Down
3 changes: 3 additions & 0 deletions test/test_readxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ def test_ws_range(self):
self.assertEqual([[11, 12, ''], ['', '', 23]], db.ws('sh1').range('A1:C2'))
self.assertEqual([[12, '', ''], ['', 23, ''], ['', '', '']], db.ws('sh1').range('B1:D3'))

self.assertEqual([[11, 12] + ['']*(xl.MAX_XL_COLS - 2)], db.ws('sh1').range('1:1'))
self.assertEqual([[11]] + [['']]*(xl.MAX_XL_ROWS - 1), db.ws('sh1').range('A:A'))

db.ws('sh1').update_address('A1', '=11')
db.ws('sh1').update_address('B1', '=12')
db.ws('sh1').update_address('C2', '=23')
Expand Down

0 comments on commit ea1539f

Please sign in to comment.