简体   繁体   English

如何将使用工作簿(openpyxl)制作的 excel 保存到 azure 存储帐户作为 python 中的 blob?

[英]How to save an excel made with workbook(openpyxl) to azure storage account as blob in python?

Consider there is an workbook we made:考虑我们制作的工作簿:

wb = Workbook()

and after writing code, we have excel created in that.在编写代码之后,我们在其中创建了 excel。 But at last, instead of wb.save("test.xslx), I want to save this excel in the azure storage account as a blob.但最后,我想将这个 excel 作为 blob 保存在 azure 存储帐户中,而不是 wb.save("test.xslx)。

I have tried saving the workbook(wb) in my azure storage account but it didn't work.我曾尝试将工作簿(wb)保存在我的 azure 存储帐户中,但没有成功。

Could you please help me how to do that?你能帮我怎么做吗?

Sample code from the Azure docs https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python :来自 Azure 文档https: //docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python 的示例代码:

# Create a local directory to hold blob data
local_path = "./data"
os.mkdir(local_path)

# Create a file in the local data directory to upload and download
local_file_name = str(uuid.uuid4()) + ".txt"
upload_file_path = os.path.join(local_path, local_file_name)

# Write text to the file
file = open(upload_file_path, 'w')
file.write("Hello, World!")
file.close()

# Create a blob client using the local file name as the name for the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=local_file_name)

print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)

# Upload the created file
with open(upload_file_path, "rb") as data:
    blob_client.upload_blob(data)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用openpyxl在普通模式下保存Excel工作簿? - How to save excel workbook in normal mode with openpyxl? 将 excel 文件 stream 保存到 azure blob 存储 - save excel file stream to azure blob storage Azure 存储帐户 blob stream 和 Python - Azure Storage Account blob stream with Python 如何从 ZA7F5F35426B627411FCA430Z 中的 Windows 异步打开 Excel 工作簿中的 Excel 与 openpy1 - How to asynchronously open an Excel Workbook in Excel in Windows from Python with openpyxl Azure:使用容器创建存储帐户并将 Blob 上传到 Python 中 - Azure: create storage account with container and upload blob to it in Python 如何使用 openpyxl / pandas 或任何 python 将从几个 excel 工作表中提取的字符串数据保存到新工作簿? - How do I save the string data I have extracted from several excel sheets to a new workbook using openpyxl / pandas or anything python? 如何将 Python 中的 openpyxl 创建的 Excel 工作表中的单元格设为“可格式化”? - How can cells in Excel worksheets created by openpyxl in Python be made 'formattable'? 在 Python 中保存 Excel 工作簿 - Save excel workbook in Python 如何从python中保存excel工作簿 - How to save an excel workbook from within python 如何在 python 脚本中创建文件而不将其存储在本地目录中并将其保存在 azure blob 存储上的不同容器中? - How to create a file in a python script without storing it in a local directory and save it in a different container on azure blob storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM