excel - Azure Blob 存储:从 Excel 工作簿中删除密码
问题描述
我在 Azure Blob 存储中保存了一个受密码保护的 Excel 工作簿,我想删除密码并将文件上传回 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);
推荐阅读
- android - 如何在同一个项目中为 android native 和 ios native 设置 codecept.conf.js
- ios - 无法获得 iPad 浮动键盘的正确高度
- amazon-web-services - AWS 错误 LimitExceededException 和 EntityAlreadyExistsException
- amazon-web-services - 桌面应用程序与 AWS S3 的集成:安全最佳实践
- java - SpringBoot 表单提交
- reactjs - 将选定的 Tab 标题值获取到变量
- reactjs - 为什么切换语言环境时我的会话不加载?
- php - 有没有办法为 HasOneThrough 生成数据透视记录
- reactjs - react 无法正确过滤对象
- java - 向控制器 JavaBean 添加不代表客户端参数的额外属性