Search code examples
c#excelapache-poinpoi

NPOI set readonly to excel


Is there a way to produce a workbook using NPOI that has doesn't allow user to edit the workbook unless saving a new copy?

Basically I want to produce a file that is a read-only excel, and that no users will have conflict when opening them when accessing them on a shared network drive.

P/S: I am not looking for password protection.

var wb = new XSSFWorkbook();
var sheet = wb.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue("Hello World");

wb.SetReadOnly(true);//Something like this?

Solution

  • Readonly is an attribute for file

    File.SetAttributes("workbook.xlsx", FileAttributes.ReadOnly);