PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
290 stars 47 forks source link

Accessing a full column, row, or sheet named range fails #79

Closed lukelamar closed 1 year ago

lukelamar commented 1 year ago

Pylightxl Version: 1.61 Python Version: 3.7.4

Summary of Bug/Feature: Excel permits a named range for a full column, row, or sheet. Accessing an existing named range for one of these fails. The format of a full column named range is in the format: Sheet1!A:A

Pylightxl expects a number following a letter and halts when parsing the address.

The workaround is to define a named range with an explicit column/row boundary; however, one may not always have permission to re-define ranges.

Traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\pylightxl\pylightxl.py in utility_address2index(address)
   2222     try:
-> 2223         row = int(strVSnum.split(address)[1])
   2224     except (IndexError, ValueError):

ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

UserWarning                               Traceback (most recent call last)
<ipython-input-28-7f447233b8b5> in <module>
      7 #xldb.ws(ws='Sheet1').nr(name='dataset_id')
      8 #xldb.nr_names
----> 9 xldb.nr('dataset_name')

C:\ProgramData\Anaconda3\lib\site-packages\pylightxl\pylightxl.py in nr(self, name, formula, output)
   1677 
   1678         ws, address = full_address.split('!')
-> 1679         return self.ws(ws).range(address, output=output)
   1680 
   1681     def nr_loc(self, name):

C:\ProgramData\Anaconda3\lib\site-packages\pylightxl\pylightxl.py in range(self, address, formula, output)
   1847         if ':' in address:
   1848             address_start, address_end = address.split(':')
-> 1849             row_start, col_start = utility_address2index(address_start)
   1850             row_end, col_end = utility_address2index(address_end)
   1851 

C:\ProgramData\Anaconda3\lib\site-packages\pylightxl\pylightxl.py in utility_address2index(address)
   2224     except (IndexError, ValueError):
   2225         raise UserWarning('pylightxl - Incorrect address ({}) entry. Address must be an alphanumeric '
-> 2226                          'where the trailing character(s) are numeric characters 1-9'.format(address))
   2227 
   2228     return [row, col]

UserWarning: pylightxl - Incorrect address (D) entry. Address must be an alphanumeric where the trailing character(s) are numeric characters 1-9

Suggestion for fix: Check for this condition when parsing.

PydPiper commented 1 year ago

Hi @lukelamar thanks for posting this. I am held up by school work at the moment, but after this weekend I should be able to take a look and will get back to you with a fix!