Is there a way to write a spreadsheetlight excel file directly to blob storage?

585 Views Asked by At

I am porting some old application services code into Microsoft Azure and need a little help.

I am pulling in some data from a stored procedure and creating a SpreadsheetLight document (this was brought in from the old code since my users want to keep the extensive formatting that was already built into this process). That code works fine, but I need to write the file directly into our azure blob container without saving a local copy first (as this process will run in a pipeline). Using some sample code I found as a guide, I was able to get it working in debug by saving locally and then uploading that out to the blob storage... but now I need to find a way to remove that local save prior to the upload.

1

There are 1 best solutions below

0
On BEST ANSWER

Well I actually stumbled on the solution.

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