ワークシートを保護するために使用されたパスワードの検証
Contents
[
Hide
]
Aspose.Cells APIは、Protectionクラスを拡張し、いくつかの有用なプロパティやメソッドを導入しました。そのようなメソッドの1つが、文字列のインスタンスとしてパスワードを指定し、ワークシートを保護するために同じパスワードが使用されているかどうかを検証するverifyPasswordです。
ワークシートを保護するために使用されたパスワードの検証
Protection.verifyPasswordメソッドは、指定されたパスワードが与えられたワークシートを保護するために使用されたパスワードと一致する場合はtrueを返し、与えられたパスワードが一致しない場合はfalseを返します。次のコードは、Protection.verifyPasswordメソッドを使用してパスワード保護を検出し、パスワードを検証することを示しています。
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(VerifyPasswordtoProtectWorksheet.class); | |
// Create an instance of Workbook and load a spreadsheet | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Access the protected Worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Check if Worksheet is password protected | |
if (sheet.getProtection().isProtectedWithPassword()) { | |
// Verify the password used to protect the Worksheet | |
if (sheet.getProtection().verifyPassword("password")) { | |
System.out.println("Specified password has matched"); | |
} else { | |
System.out.println("Specified password has not matched"); | |
} | |
} |