检测工作表是否受密码保护
Contents
[
Hide
]
可以分别保护工作簿和工作表。例如,电子表格可能包含一个或多个受密码保护的工作表,但是,电子表格本身可能会或可能不会受到保护。 Aspose.Cells API 提供了检测给定工作表是否受密码保护的方法。本文演示了使用 Aspose.Cells for .NET API 来实现相同的目的。
Aspose.Cells for .NET 8.7.0暴露了保护.IsProtectedWithPassword属性来检测工作表是否受密码保护。布尔型保护.IsProtectedWithPassword财产回报真的如果工作表受密码保护,并且错误的如果不。
This file contains hidden or 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"); | |
} |