2017-06-13 104 views
0

我使用Google Drive API创建.csv,我在“Drive”显示中看到它,但我在“表格”中看不到它。我怎样才能让它显示在表格中?这里是我的代码:在Python中创建Google表格

credentials = get_credentials() 
http = credentials.authorize(httplib2.Http()) 
service = discovery.build('drive', 'v3', http=http) 

results = service.files().create(body={"name":"Test7.csv"}, media_body='/tmp/inputfile.csv', keepRevisionForever=None, useContentAsIndexableText=None, supportsTeamDrives=None, ocrLanguage=None, ignoreDefaultVisibility=None).execute() 
+0

您可能要到'convert'参数添加到TRUE;当[上传](https://开头开发商.google.com/drive/v2/reference/files/insert)该文件将触发是否将此文件转换为相应的Google文档格式。你可以查看这个[GitHub](https://gist.github.com/9b/5608784)来查看python中的实现。希望这可以帮助。 –

回答

-1

看起来你只是将一个CSV文件添加到驱动器。

你需要指定MIME类型为谷歌电子表格:

from apiclient.http import MediaFileUpload 

file_metadata = { 
    'name' : 'My Report', 
    'mimeType' : 'application/vnd.google-apps.spreadsheet' 
} 

media = MediaFileUpload('test7.csv', 
         mimetype='text/csv', 
         resumable=True) 

file = drive_service.files().create(body=file_metadata, 
            media_body=media, 
            fields='id').execute() 

https://developers.google.com/drive/v3/web/manage-uploads#importing_to_google_docs_types_wzxhzdk18wzxhzdk19

+0

尽管这个链接可能回答这个问题,但最好在这里包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/16404525) –

+0

@JohnMoutafis增加了代码示例,谢谢。 –

+0

行@ChrisLam,我正在收回我的国旗! –