检测工作表是否受密码保护
Contents
[
Hide
]
可以分别保护工作簿和工作表。例如,电子表格可能包含一个或多个受密码保护的工作表,但电子表格本身可能受保护,也可能不受保护。Aspose.Cells API提供了检测给定工作表是否受密码保护的方法。本文演示了使用 Aspose.Cells for .NET API 实现相同功能的用法。
Aspose.Cells for .NET 8.7.0已公开了Protection.IsProtectedWithPassword属性,用于检测工作表是否受密码保护。布尔型Protection.IsProtectedWithPassword属性返回 true 如果工作表被密码保护,false 如果没有。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create an instance of Workbook and load a spreadsheet | |
var book = new Workbook(dataDir + "sample.xlsx"); | |
// Access the protected Worksheet | |
var sheet = book.Worksheets[0]; | |
// Check if Worksheet is password protected | |
if (sheet.Protection.IsProtectedWithPassword) | |
{ | |
Console.WriteLine("Worksheet is password protected"); | |
} | |
else | |
{ | |
Console.WriteLine("Worksheet is not password protected"); | |
} |