[英]NPOI set readonly to excel
有沒有一種方法可以使用NPOI生成工作簿,除非保存新副本,否則該工作簿不允許用戶編輯工作簿?
基本上,我想生成一個只讀excel文件,並且在共享網絡驅動器上訪問它們時,打開它們時沒有用戶會有沖突。
P / S:我不是在尋求password
保護。
var wb = new XSSFWorkbook();
var sheet = wb.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue("Hello World");
wb.SetReadOnly(true);//Something like this?
只讀是文件的屬性
File.SetAttributes("workbook.xlsx", FileAttributes.ReadOnly);
您不需要NPOI庫
為目錄中的所有文件設置安全權限
var directory = new DirectoryInfo(folderPath);
foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
{
File.SetAttributes(folderPath, FileAttributes.ReadOnly);
}
或特定文件
File.SetAttributes(folderPath, FileAttributes.ReadOnly);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.