Erkennen, ob Arbeitsblatt passwortgeschützt ist
Contents
[
Hide
]
Es ist möglich, die Arbeitsmappen und Arbeitsblätter getrennt zu schützen. Beispielsweise kann eine Tabelle ein oder mehrere Arbeitsblätter enthalten, die passwortgeschützt sind, während die Tabelle selbst geschützt sein kann oder auch nicht. Die Aspose.Cells-APIs bieten die Möglichkeit zu erkennen, ob ein bestimmtes Arbeitsblatt passwortgeschützt ist oder nicht. In diesem Artikel wird die Verwendung der Aspose.Cells for .NET-API zur Erreichung desselben demonstriert.
Aspose.Cells for .NET 8.7.0 hat die Protection.IsProtectedWithPassword-Eigenschaft freigegeben, um zu erkennen, ob ein Arbeitsblatt passwortgeschützt ist oder nicht. Die boolesche Eigenschaft Protection.IsProtectedWithPassword gibt true zurück, wenn Worksheet passwortgeschützt ist, und false, wenn nicht.
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"); | |
} |