Created
October 23, 2023 09:24
-
-
Save fileformat-cells-gists/605ca75c6da1a35c3436b4e065b88087 to your computer and use it in GitHub Desktop.
Un-Protect all worksheets with in a Workbook in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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