Skip to content

UsedRange not supported in Worksheet #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AngPeiHao opened this issue Dec 19, 2024 · 2 comments
Closed

UsedRange not supported in Worksheet #926

AngPeiHao opened this issue Dec 19, 2024 · 2 comments

Comments

@AngPeiHao
Copy link

It seems like UsedRange is not supported and not specifying the range through .range() returns None.

worksheets["test_sheet"].range().execute_query() returns None.

https://learn.microsoft.com/en-us/graph/api/worksheet-usedrange?view=graph-rest-1.0&tabs=http

@AngPeiHao
Copy link
Author

Solution:

# Office365-REST-Python-Client/office365/onedrive/workbooks/worksheets/worksheet.py
class WorkbookWorksheet(Entity):
    ...
    def used_range(self):
        """Gets the used range object of the worksheet"""
        return_type = WorkbookRange(
            self.context, ResourcePath("range", self.resource_path)
        )
        qry = FunctionQuery(self, "usedRange", return_type=return_type)
        self.context.add_query(qry)
        return return_type
    ...
# Office365-REST-Python-Client/examples/onedrive/excel/read_range.py

# Get the smallest range of cells that have any values or formatting assigned to them
worksheet_range = worksheets["Sheet1"].used_range().execute_query()

@vgrem
Copy link
Owner

vgrem commented Apr 11, 2025

The support for used range has been introduced in 2.6.0 version.

Example:

worksheet_range = worksheets["Sheet1"].range().execute_query()

or

worksheet_range = worksheets["Sheet1"].range(address="A1:B3").execute_query()

read_range.py

@vgrem vgrem closed this as completed Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants