Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created December 15, 2020 01:42
Protect Excel Files in C#
// Open the Excel file
Workbook workbook = new Workbook("Excel.xlsx");
// Protect workbook by specifying protection type
workbook.Protect(ProtectionType.All, "12345");
// Save the file
workbook.Save("Excel.xlsx");
// Open the Excel file
Workbook workbook = new Workbook("Excel.xlsx");
// Unprotect workbook
workbook.Unprotect("12345");
// Set password to null
workbook.Settings.Password = null;
// Save the file
workbook.Save("Excel.xlsx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment