0

can we create password protected excel workbook or sheet with 'Officewriter' API? My requirement is to create pwd protected excel programatically (c#) with out having to install office in the servers. I have tried with openXML but the when password protected the file is showing as corrupted and not opening. Anybody let me know if this is possible with 'Officewriter'.

1 Answers1

3

Note: I work for SoftArtisans, makers of OfficeWriter.

Yes, it is possible to password protect an Excel workbook programmatically with OfficeWriter.

If you are using our ExcelApplication API to programmatically manipulate a workbook, you can protect workbooks and worksheets.

Workbook.Protect(string) will protect the structure of the workbook with the supplied password. For example, users won't be able to add or remove worksheets without the password.

Worksheet.Protect(string) write-protects the worksheet so users cannot modify the worksheet in Excel without entering the password.

ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Open("myWorkbook.xlsx");

wb.Protect("workbookPassword");
wb.Worksheets["Sheet1"].Protect("worksheetPassword");

xla.Save(wb, "myWorkbook_output.xlsx");

If you are using our ExcelTemplate API to bind data to a template that contains placeholder markers, you can set ExcelTemplate.EncryptPassword which will encrypt the workbook with the given password using RC4 encryption.

 ExcelTemplate xlt = new ExcelTemplate();
 xlt.Open("template.xlsx");
 ...
 xlt.EncryptPassword = "MyPassword";
 xlt.Process();
 xlt.Save("output.xlsx");
AlisonB
  • 395
  • 1
  • 6