Passwort zum Ändern mit Aspose.Cells überprüfen

Passwort zum Ändern in Microsoft Excel überprüfen

Sie können beim Erstellen Ihrer Arbeitsbücher in Microsoft Excel Passwort zum Öffnen und Passwort zum Ändern zuweisen. Bitte sehen Sie sich diesen Screenshot an, der die Benutzeroberfläche zeigt, die Microsoft Excel zum Angeben dieser Passwörter bereitstellt.

todo:image_alt_text

Überprüfen Sie das Kennwort zur Änderung mit Aspose.Cells

Die folgenden Beispielscodes laden die Quell-Excel-Datei. Sie hat ein Passwort zum Öffnen als 1234 und ein Passwort zum Ändern als 5678. Der Code überprüft zunächst, ob 567 das richtige Passwort zum Ändern ist, und gibt false zurück, und dann überprüft er, ob 5678 das Passwort zum Ändern ist, und gibt true zurück.

// 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 Beispielscodes nach dem Laden der Quell-Excel-Datei.

Is 567 correct Password to modify: False

Is 5678 correct Password to modify: True