【问题标题】:Is there a way to write a spreadsheetlight excel file directly to blob storage?有没有办法将电子表格 excel 文件直接写入 blob 存储?
【发布时间】:2021-11-09 23:40:42
【问题描述】:
我正在将一些旧的应用程序服务代码移植到 Microsoft Azure 中,需要一些帮助。
我正在从存储过程中提取一些数据并创建一个 SpreadsheetLight 文档(这是从旧代码中引入的,因为我的用户希望保留该过程中已经内置的大量格式)。该代码工作正常,但我需要将文件直接写入我们的 azure blob 容器,而无需先保存本地副本(因为此过程将在管道中运行)。使用我找到的一些示例代码作为指南,我能够通过在本地保存然后将其上传到 blob 存储来使其在调试中工作......但现在我需要找到一种方法来在上传。
【问题讨论】:
标签:
azure
.net-core
azure-blob-storage
spreadsheetlight
【解决方案1】:
其实我偶然发现了解决方案。
string connectionString = "YourConnectionString";
string containerName = "YourContainerName";
string strFileNameXLS = "YourOutputFile.xlsx";
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = blobContainerClient.GetBlobClient(strFileNameXLS);
SLDocument doc = YourSLDocument();
using (MemoryStream ms = new MemoryStream())
{
doc.SaveAs(ms);
ms.Position = 0;
await blobClient.UploadAsync(ms, true);
ms.Close();
}