Creating empty spreadsheets in Google Drive using Drive API

后端 未结 5 1627
醉话见心
醉话见心 2020-12-02 19:38

I want to create an empty Google Sheet (created only with metadata) in Google Drive. When I referred to the Google SpreadSheet API documentation, it says to use the Document

5条回答
  •  一生所求
    2020-12-02 20:04

    The proposed methods did not work for me, but the following code works:

    # requires: uid='example@gmail.com', pass1='password', 
    # name_spr='name_of_spreadsheet'
    
    import gdata.docs.client
    
    docs_client = gdata.docs.client.DocsClient()
    docs_client.ClientLogin(uid, pass1, 'any')
    document = gdata.docs.data.Resource(type='spreadsheet', title=name_spr)
    resource = docs_client.CreateResource(document)
    full_id = resource.resource_id.text # returned by gdata
    gs_id = full_id[len('spreadsheet:'):]
    

提交回复
热议问题