O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.66k stars 420 forks source link

Feature Request: Create excel worksheets #1104

Open keithknott26 opened 3 weeks ago

keithknott26 commented 3 weeks ago

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!

alejcas commented 2 weeks ago

I don't have the time to include this but PR are very welcome.

Thanks