[英]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.