Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fileformat-cells-gists/605ca75c6da1a35c3436b4e065b88087 to your computer and use it in GitHub Desktop.
Save fileformat-cells-gists/605ca75c6da1a35c3436b4e065b88087 to your computer and use it in GitHub Desktop.
Un-Protect all worksheets with in a Workbook in C#
using FileFormat.Cells;
class Program
{
static void Main(string[] args)
{
// Define the path to the existing spreadsheet
string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx";
// Open the existing workbook specified by the filePath
using (Workbook wb = new Workbook(filePath))
{
// Iterate through each worksheet in the workbook
foreach (var worksheet in wb.Worksheets)
{
// Check if the current worksheet is protected
if (worksheet.IsProtected())
{
// Display the name of the protected worksheet
Console.WriteLine("Protect Sheet Name = " + worksheet.Name);
// Remove protection from the current worksheet
worksheet.UnprotectSheet();
}
}
// Save the changes made to the workbook back to the file
wb.Save(filePath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment