python-o365
python-o365 copied to clipboard
Feature Request: Create excel worksheets
Hi,
Firstly thank you for all your hard work on this project I use it often.
Would you kindly include the creation of excel worksheets into excel.py so we can get, create, update, and delete workbooks? Today I see it handles only get, update, and delete.
here's a modification to excel.py to handle this: `class WorkSheet(ApiComponent): """ An Excel WorkSheet """
_endpoints = {
'get_tables': '/tables',
'get_table': '/tables/{id}',
'get_range': '/range',
'add_table': '/tables/add',
'get_used_range': '/usedRange(valuesOnly={})',
'get_cell': '/cell(row={row},column={column})',
'add_named_range': '/names/add',
'add_named_range_f': '/names/addFormulaLocal',
'get_named_range': '/names/{name}',
'create_worksheet': '/worksheets'
}
# Existing constructors and methods...
def create_worksheet(self, name):
"""
Creates a new worksheet in the workbook with the specified name.
:param str name: The name of the new worksheet.
:return: The newly created WorkSheet instance.
"""
url = self.build_url(self._endpoints.get('create_worksheet'))
data = {'name': name}
response = self.session.post(url, json=data)
if not response:
logging.error(f"Failed to create worksheet '{name}'")
return None
return WorkSheet(parent=self.workbook, **{self._cloud_data_key: response.json()})
`
For now I'll have to work around this until it's included, appreciate your help!
I don't have the time to include this but PR are very welcome.
Thanks
Trying to help out a bit this morning. I do not understand this request. The correct method exists in the WorkBook (where it belongs) since 2019.
It works just fine in my project and creates a worksheet at the WorkBook level.
I think the requester should keep an instance of WorkBook at hand and invoke add_worksheet in their code.
@keithknott26 Does this make sense to you and does that help?
@alejcas Otherwise, I think this is a closed ticket.