【问题标题】: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 存储来使其在调试中工作......但现在我需要找到一种方法来在上传。

【问题讨论】:

  • 几个月前我发现这个人问了同样的问题,但唯一的答案是我已经开始工作的解决方案......希望有更好的方法。 (注意:我会在帖子上添加评论,但我还没有能够做到这一点的声誉点)。 stackoverflow.com/questions/65692431/…

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

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 2012-09-24
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 2017-05-18
    • 1970-01-01
    相关资源
    最近更新 更多