我正在用Excel导出一些数据。一切正常。但是现在的要求是将相同的excel文件上传到Blob存储中。如果提供静态文件,则可以直接在blob中上传文件。但是,能否请您帮我,我该如何将其上传到Blob而不是导出,或者如果可以的话,请分享您的想法。下面是我的导出代码。
public void ExportToExcel(DataTable table)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
ExcelPackage excel = new ExcelPackage();
var workSheet = excel.Workbook.Worksheets.Add(ddlModel.SelectedItem.Text + "_Support");
var totalCols = table.Columns.Count;
var totalRows = table.Rows.Count;
try
{
for (var col = 1; col <= totalCols; col++)
{
workSheet.Cells[1, col].Value = table.Columns[col - 1].ColumnName;
workSheet.Cells[1, col].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
workSheet.Cells[1, col].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
workSheet.Cells[1, col].Style.Font.Color.SetColor(System.Drawing.Color.Blue);
workSheet.Cells[1, col].Style.Font.Bold = true;
workSheet.Cells[1, col].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
workSheet.Cells[1, col].Style.WrapText = false;
workSheet.Cells[1, col].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);//Applying Borders
workSheet.Cells[1, col].AutoFitColumns(30);
}
for (var row = 1; row <= totalRows; row++)
{
for (var col = 0; col < totalCols; col++)
{
workSheet.Cells[row + 1, col + 1].Value = table.Rows[row - 1][col];
workSheet.Cells[row + 1, col + 1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
workSheet.Cells[row + 1, col + 1].AutoFitColumns(30);
}
}
}
catch (Exception ex)
{
ExceptionLogging.SendErrorToText(ex);
Response.Redirect("~/CustomErrors/CustomError.aspx");
}
using (var memoryStream = new MemoryStream())
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=" + ddlModel.SelectedItem.Text + "_support" + ".xlsx");
excel.SaveAs(memoryStream);
memoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
这是我要传递文件URL的blob方法。
BlobStorageFunctions.CallBlobGettingStartedSamples(fileURL).
请提出建议。