Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created December 15, 2020 01:42
Show Gist options
  • Save aspose-com-gists/8d4da2809d6fd2a87f994b2890a21d98 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8d4da2809d6fd2a87f994b2890a21d98 to your computer and use it in GitHub Desktop.
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