Skip to content

Commit bc8b530

Browse files
committed
Add valuesOnly parameter to Excel 'get_used_range' request endpoint for both Range and WorkSheet classes
1 parent 4dfed72 commit bc8b530

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

O365/excel.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class Range(ApiComponent):
483483
'get_row': '/row',
484484
'rows_above': '/rowsAbove(count={})',
485485
'rows_below': '/rowsBelow(count={})',
486-
'get_used_range': '/usedRange',
486+
'get_used_range': '/usedRange(valuesOnly={})',
487487
'clear_range': '/clear',
488488
'delete_range': '/delete',
489489
'insert_range': '/insert',
@@ -761,11 +761,12 @@ def get_rows_below(self, rows=1):
761761
def get_used_range(self, only_values=True):
762762
"""
763763
Returns the used range of the given range object.
764-
:param bool only_values: Optional.
765-
Considers only cells with values as used cells.
764+
:param bool only_values: Optional. Defaults to True.
765+
Considers only cells with values as used cells (ignores formatting).
766766
:return: Range
767767
"""
768-
return self._get_range('get_used_range', valuesOnly=only_values)
768+
# Format the "only_values" parameter as a lowercase string to work correctly with the Graph API
769+
return self._get_range('get_used_range', str(only_values).lower())
769770

770771
def clear(self, apply_to='all'):
771772
"""
@@ -1480,7 +1481,7 @@ class WorkSheet(ApiComponent):
14801481
'get_table': '/tables/{id}',
14811482
'get_range': '/range',
14821483
'add_table': '/tables/add',
1483-
'get_used_range': '/usedRange',
1484+
'get_used_range': '/usedRange(valuesOnly={})',
14841485
'get_cell': '/cell(row={row},column={column})',
14851486
'add_named_range': '/names/add',
14861487
'add_named_range_f': '/names/addFormulaLocal',
@@ -1614,11 +1615,15 @@ def get_range(self, address=None):
16141615
return None
16151616
return self.range_constructor(parent=self, **{self._cloud_data_key: response.json()})
16161617

1617-
def get_used_range(self):
1618+
def get_used_range(self, only_values=True):
16181619
""" Returns the smallest range that encompasses any cells that
16191620
have a value or formatting assigned to them.
1621+
:param bool only_values: Optional. Defaults to True.
1622+
Considers only cells with values as used cells (ignores formatting).
1623+
:return: Range
16201624
"""
1621-
url = self.build_url(self._endpoints.get('get_used_range'))
1625+
# Format the "only_values" parameter as a lowercase string to work properly with the Graph API
1626+
url = self.build_url(self._endpoints.get('get_used_range').format(str(only_values).lower()))
16221627
response = self.session.get(url)
16231628
if not response:
16241629
return None

0 commit comments

Comments
 (0)