Что касается проблемы, обратитесь к следующему коду
- Загрузить
string accountName = "jimtestdiag924";
string accountKey = "uxz4AtF0*********yDSZ7Q+A==";
var credential = new StorageSharedKeyCredential(accountName, accountKey);
string url = string.Format("https://{0}.blob.core.windows.net/", accountName);
var blobServiceClient =new BlobServiceClient(new Uri(url), credential);
var containerClient = blobServiceClient.GetBlobContainerClient("testupload");
var blobClient =containerClient.GetBlobClient("test.xlsx");
BlobDownloadInfo download = await blobClient.DownloadAsync();
using (var ms = new MemoryStream()) {
await download.Content.CopyToAsync(ms);
using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(ms, true))
{
// Access the main Workbook part, which contains all references.
WorkbookPart workbookPart = spreadSheet.WorkbookPart;
// get sheet by name
Sheet sheet = workbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == "Sheet1").FirstOrDefault();
// get worksheetpart by sheet id
WorksheetPart worksheetPart = workbookPart.GetPartById(sheet.Id.Value) as WorksheetPart;
Cell cell = GetCell(worksheetPart.Worksheet, "B", 4);
cell.CellValue = new CellValue("10");
cell.DataType = new EnumValue<CellValues>(CellValues.Number);
// Save the worksheet.
worksheetPart.Worksheet.Save();
// for recacluation of formula
spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;
spreadSheet.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;
}
// upload file to another contanier
ms.Position = 0;
containerClient = blobServiceClient.GetBlobContainerClient("test");
await containerClient.CreateIfNotExistsAsync();
blobClient = containerClient.GetBlobClient("test.xlsx");
await blobClient.UploadAsync(ms);
download.Content.Close();
}
Скачать
string accountName = "jimtestdiag924";
string accountKey = "uxz4AtF0*********yDSZ7Q+A==";
var credential = new StorageSharedKeyCredential(accountName, accountKey);
string url = string.Format("https://{0}.blob.core.windows.net/", accountName);
var blobServiceClient =new BlobServiceClient(new Uri(url), credential);
var containerClient = blobServiceClient.GetBlobContainerClient("test");
var blobClient = containerClient.GetBlobClient("test.xlsx");
BlobDownloadInfo download = await blobClient.DownloadAsync();
using (var file = File.Create(@"D:\test.xlsx")) {
await download.Content.CopyToAsync(file);
download.Content.Close();
}
Исходный файл excel
The new excel file
введите описание изображения здесь