【问题标题】:How to create and write to an XLSX file on Google Cloud Storage如何在 Google Cloud Storage 上创建和写入 XLSX 文件
【发布时间】:2019-02-15 08:31:53
【问题描述】:

我在 Google Cloud Storage 上处理 XLSX 文件时遇到问题。以下代码是我目前所拥有的:

import cloudstorage

mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
filehandle = cloudstorage.open('/default/temp_export.xlsx', 'w', content_type=mime)
filehandle.write('some data1,some data2\n')
filehandle.write('some data3, somedata4\n')
filehandle.close()

这将在我的存储桶上创建一个使用 mime 类型的 XLSX 格式的 XLSX 文件temp_export.xlsx。当我尝试使用以下命令读取文件时,它工作正常:

import cloudstorage

filehandle = cloudstorage.open('/default/temp_export.xlsx')
print filehandle.read()

# Output:
# some data1,some data2
# some data3, somedata4

但是当我尝试去我的存储桶并下载 temp_export.xlsx 并尝试打开它时,它会抛出这个 excel 错误:

Excel cannot open this file.
The file format or file extension is not valid. 
Verify that the file has not been corrupted and that 
the file extension matches the format of the file.

任何人都知道我做错了什么或如何解决它?谢谢。

【问题讨论】:

标签: google-cloud-platform google-cloud-storage


【解决方案1】:

有什么理由不将latest library 用于云存储?那个仅适用于带有 Python 2.7 的 App Engine。

有关于如何上传对象的an example herehow to download it,然后您必须阅读带有适当库的xlsx 文件,例如the ones mentioned here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 2018-11-17
    • 2012-01-02
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    相关资源
    最近更新 更多