是否有一种方法可以直接将电子表格轻excel文件写入blob存储?



我正在将一些旧的应用程序服务代码移植到Microsoft Azure中,需要一些帮助。

我正在从存储过程中拉入一些数据并创建一个SpreadsheetLight文档(这是从旧代码中引入的,因为我的用户希望保留已经内置到此过程中的广泛格式)。该代码工作良好,但我需要将文件直接写入我们的azure blob容器,而不需要首先保存本地副本(因为此过程将在管道中运行)。使用我找到的一些示例代码作为指导,我能够通过本地保存然后上传到blob存储来调试它。但是现在我需要找到一种方法在上传之前删除本地保存。

其实我是偶然发现了解决办法。

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();
}

最新更新