Azure Blob 存储:从 excel 工作簿中删除密码
Azure Blob Storage: Remove password from excel workbook
我有一个受密码保护的 excel 工作簿保存在 Azure Blob 存储中,我想删除密码并将文件上传回 Blob。我编写了密码保护 blob 中的 excel 文件的代码,但我是 C# 的新手,打开密码保护的文件作为流会生成错误。
有没有人成功地从保存在 Azure Blob 存储中的 excel 文件中删除密码?
//Open Excel on blob
BlobServiceClient blobServiceClient = new BlobServiceClient(appsetting);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = containerClient.GetBlobClient(fileName);
//Password protect file
using (var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(true)))
using (ExcelPackage package = new ExcelPackage(stream))
{
//Save password protected file
package.Save(password);
MemoryStream ms = new MemoryStream(package.GetAsByteArray());
ms.Position = 0;
//Delete the unprotected excel file
blobClient.DeleteIfExists();
//Upload password protected excel file
BlobClient outputBlob = containerClient.GetBlobClient(fileName);
outputBlob.Upload(ms);
}
通过保存到 Azure 上的临时文件夹然后打开文件解决。
//Create temp path
string tempPath = Path.GetTempPath();
tempFullPath = tempPath + fileName;
//Download blob
blobClient.DownloadTo(tempFullPath);
我有一个受密码保护的 excel 工作簿保存在 Azure Blob 存储中,我想删除密码并将文件上传回 Blob。我编写了密码保护 blob 中的 excel 文件的代码,但我是 C# 的新手,打开密码保护的文件作为流会生成错误。
有没有人成功地从保存在 Azure Blob 存储中的 excel 文件中删除密码?
//Open Excel on blob
BlobServiceClient blobServiceClient = new BlobServiceClient(appsetting);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = containerClient.GetBlobClient(fileName);
//Password protect file
using (var stream = await blobClient.OpenReadAsync(new BlobOpenReadOptions(true)))
using (ExcelPackage package = new ExcelPackage(stream))
{
//Save password protected file
package.Save(password);
MemoryStream ms = new MemoryStream(package.GetAsByteArray());
ms.Position = 0;
//Delete the unprotected excel file
blobClient.DeleteIfExists();
//Upload password protected excel file
BlobClient outputBlob = containerClient.GetBlobClient(fileName);
outputBlob.Upload(ms);
}
通过保存到 Azure 上的临时文件夹然后打开文件解决。
//Create temp path
string tempPath = Path.GetTempPath();
tempFullPath = tempPath + fileName;
//Download blob
blobClient.DownloadTo(tempFullPath);