小编LMS*_*rma的帖子

使用 PyDrive 上传 XLSX 并将其转换为 Google 表格

我正在尝试将 .xlsx 文件上传到谷歌驱动器。我可以上传它。但是当我们尝试在 Drive 中打开同一个文件时,它必须使用 Google Sheets 打开。因此,它会创建一个同名的新文件并占用驱动器空间。

我想我需要在上传时更改 MimeType。

我尝试过的是:

file = drive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": FolderID}]
                        ,'title': fileName
                        ,'mimeType':'application/vnd.ms-excel'})
file.SetContentFile('12dec2018.xlsx')
file.Upload()
Run Code Online (Sandbox Code Playgroud)

我也试过这个

'mimeType':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
Run Code Online (Sandbox Code Playgroud)

在 Google文档中

我找到了另一个 MimeType

'mimeType':'application/vnd.google-apps.spreadsheet'
Run Code Online (Sandbox Code Playgroud)

但它给了我错误

ApiRequestError:https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&alt=json 返回“提供的 MIME 类型无效”>

请建议我如何才能达到理想的结果。

python google-api pydrive google-sheets-api

4
推荐指数
1
解决办法
1303
查看次数

标签 统计

google-api ×1

google-sheets-api ×1

pydrive ×1

python ×1