Skip to content
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

Creating and writing to a Google Spreadsheet inside a folder #95

Open
Mahima-ai opened this issue May 22, 2023 · 2 comments
Open

Creating and writing to a Google Spreadsheet inside a folder #95

Mahima-ai opened this issue May 22, 2023 · 2 comments

Comments

@Mahima-ai
Copy link

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
Copy link
Author

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

@aiguofer
Copy link
Owner

aiguofer commented Jun 1, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants