gspread-pandas icon indicating copy to clipboard operation
gspread-pandas copied to clipboard

Creating and writing to a Google Spreadsheet inside a folder

Open Mahima-ai opened this issue 2 years ago • 2 comments

My usecase is to write a dataframe to a Google Spreadsheet 'UseCase' inside a folder 'Testing'.

I tried the following: spread = Spread(spread='/Testing/Usecase', create_spread=True)

This creates a spreadsheet with the name '/Testing/Usecase' as seen using the Client object.

client=Client(load_dirs=True)
client.list_spreadsheet_files_in_folder('0AMdkqF6BUiexUk9PVA')

This is obvious as the functionality is to either provide the Spreadsheet name or the id in the Spread object.

I want to ask is there any way by which I can give the path of the Spreadsheet so that I am able to create the Spreadsheet inside a folder.

Mahima-ai avatar May 22 '23 08:05 Mahima-ai

My usecase is to write a dataframe to a Google Spreadsheet 'UseCase' inside a folder 'Testing'.

I tried the following: spread = Spread(spread='/Testing/Usecase', create_spread=True)

This creates a spreadsheet with the name '/Testing/Usecase' as seen using the Client object.

client=Client(load_dirs=True)
client.list_spreadsheet_files_in_folder('0AMdkqF6BUiexUk9PVA')

This is obvious as the functionality is to either provide the Spreadsheet name or the id in the Spread object.

I want to ask is there any way by which I can give the path of the Spreadsheet so that I am able to create the Spreadsheet inside a folder.

I am able to do this using the move function as below:

spread = Spread('Usecase', create_spread=True)
    spread.move('Testing')

Here, Testing is a shared folder.

Now, when I try to transfer the ownership of this Usecase file, it displays APIError: {'code': 403, 'message': "The transferOwnership parameter must be enabled when the permission role is 'owner'.", 'errors': [{'message': "The transferOwnership parameter must be enabled when the permission role is 'owner'.", 'domain': 'global', 'reason': 'forbidden', 'location': 'transferOwnership', 'locationType': 'parameter'}]}

On investigating the code, I think there must be a mechanism to pass/add parameters like 'transferOwnership' over here https://github.com/burnash/gspread/blob/2ee515e7908451c3a603ad65534a23a518fcbd68/gspread/client.py#L519

Mahima-ai avatar May 22 '23 11:05 Mahima-ai

Hey, sorry for the delayed response. I'm glad you figured out how to move the file! I think using a path in the file name when creating the spreadsheet parses the path and creates it, but I'd have to double check.

As for the ownership transfer, what function are you calling and what values are you passing in? I'm guessing something like spread.add_permission('<email>|owner|')?

I agree that's the best place to add the logic. Based on the docs, it seems like a simple:

if role == "owner":
    params["transferOwnership"] = "true"

If you want to make that PR with the gspread project that'd be great!

aiguofer avatar Jun 01 '23 05:06 aiguofer