Überprüfen Sie das zu ändernde Passwort mit Aspose.Cells
Contents
[
Hide
]
Manchmal müssen Sie überprüfen, ob das angegebene Passwort mit dem übereinstimmtZu änderndes Passwort programmatisch. Aspose.Cells stellt die Methode WorkbookSettings.WriteProtection.ValidatePassword() bereit, mit der Sie überprüfen können, ob das angegebene zu ändernde Passwort korrekt ist oder nicht.
Aktivieren Sie das zu ändernde Passwort in Microsoft Excel
Sie können zuweisenPasswort zum öffnen undZu änderndes Passwort beim Erstellen Ihrer Arbeitsmappen in Microsoft Excel. Bitte sehen Sie sich diesen Screenshot an, der die Schnittstelle Microsoft zeigt, die Excel bereitstellt, um diese Passwörter anzugeben.
![]() |
---|
Überprüfen Sie das zu ändernde Passwort mit Aspose.Cells
Die folgenden Beispielcodes laden dieQuelle Excel Datei. Es hat ein Passwort zum Öffnen als 1234 und ein Passwort zum Ändern als 5678. Der Code prüft zuerst, ob 567 das richtige Passwort zum Ändern ist, und gibt falsch zurück, und dann prüft er, ob 5678 das zu ändernde Passwort ist, und es gibt wahr zurück.
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); | |
// Specify password to open inside the load options | |
LoadOptions opts = new LoadOptions(); | |
opts.Password = "1234"; | |
// Open the source Excel file with load options | |
Workbook workbook = new Workbook(dataDir + "sampleBook.xlsx", opts); | |
// Check if 567 is Password to modify | |
bool ret = workbook.Settings.WriteProtection.ValidatePassword("567"); | |
Console.WriteLine("Is 567 correct Password to modify: " + ret); | |
// Check if 5679 is Password to modify | |
ret = workbook.Settings.WriteProtection.ValidatePassword("5678"); | |
Console.WriteLine("Is 5678 correct Password to modify: " + ret); |
Konsolenausgabe
Hier ist die Konsolenausgabe des obigen Beispielcodes nach dem Laden derQuelle Excel Datei.
Is 567 correct Password to modify: False
Is 5678 correct Password to modify: True