代码之家  ›  专栏  ›  技术社区  ›  CozyAzure

NPOI将只读设置为excel

  •  0
  • CozyAzure  · 技术社区  · 7 年前

    基本上,我希望生成一个只读的excel文件,并且当用户在共享网络驱动器上访问它们时,打开它们时不会有冲突。

    附言:我不是在找你 password 保护。

    var wb = new XSSFWorkbook();
    var sheet = wb.CreateSheet("Sheet1");
    sheet.CreateRow(0).CreateCell(0).SetCellValue("Hello World");
    
    wb.SetReadOnly(true);//Something like this?
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   shingo    7 年前

    Readonly是文件的一个属性

    File.SetAttributes("workbook.xlsx", FileAttributes.ReadOnly);
    
        2
  •  0
  •   Idriss Benbassou    7 年前

    为目录中的所有文件设置安全权限

    var directory = new DirectoryInfo(folderPath);
    foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
    {
     File.SetAttributes(folderPath, FileAttributes.ReadOnly);
    }
    

    File.SetAttributes(folderPath, FileAttributes.ReadOnly);