【问题标题】:Conver Excel to Google Spreadsheet将 Excel 转换为 Google 电子表格
【发布时间】:2020-07-19 10:38:39
【问题描述】:

我有一个 excel 文件,它包含一张包含图像的表格。我需要使用 python 将此 excel 文件转换为 google 电子表格。

我可以使用 api 创建谷歌电子表格并添加我的文本数据,但我不能添加图像。这种方式不适合我。

但我可以生成包含图像的 excel 文件。现在我需要将 excel 表导出到谷歌电子表格。

我该怎么做?

【问题讨论】:

    标签: python excel google-sheets converters


    【解决方案1】:

    您可以使用 DRIVE API 方法 Files: copy 将 Excel 文件转换为 Google 表格文件

    您只需要知道fileId 并指定选项convert=true

    示例:

    service.files().copy(fileId=file_id,convert=true, body={"title": "Chose a title"}).execute()
    

    如果您的 excel 文件在本地光盘上 - 将其上传到 Google 表格文件,如下所示:

    file_metadata = {
        'name': 'Desired Name',
        'mimeType': 'application/vnd.google-apps.spreadsheet'
    }
    media = MediaFileUpload('files/myExcelFile.xls',
                            mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                            resumable=True)
    file = drive_service.files().create(body=file_metadata,
                                        media_body=media,
                                        fields='id').execute()
    print 'The converted file is on your Google Drive and has the Id: %s' % file.get('id')
    

    更多信息herehere

    【讨论】:

    • 什么是file_id?我有本地 excel 文件。
    • 你的意思是你把它放在你的本地磁盘而不是谷歌驱动器上?
    猜你喜欢
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2017-05-28
    • 1970-01-01
    • 2013-05-04
    • 2011-07-21
    • 1970-01-01
    相关资源
    最近更新 更多