简体   繁体   中英

Python - Using gspread to create a spreadsheet in a specific folder in Google Drive

I'm trying to create a new spreadsheet using gspread, and I want to be able to control where it ends up.

    gc = gspread.authorize(credentials)

    sheetname = 'Test sheet'
    sheet = gc.create(sheetname)

I think that what's happening is that when I do gc.create(sheetname), it's making it in my Google service account, but I want it to end up in a specific folder in my normal account.

-

--Figured it out--

Needed to change to the following:

if parent_folder_ids:
    body["parents"] = parent_folder_ids

You may refer with this tutorial .

def create_google_spreadsheet(title: str, parent_folder_ids: list=None, share_domains: list=None) -> Spreadsheet:
    """Create a new spreadsheet and open gspread object for it.

Be noted that created spreadsheet is not instantly visible in your Drive search and you need to access it by direct link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM