Aspose.Cells を使用して変更するパスワードを確認してください
Contents
[
Hide
]
割り当てることができます開くためのパスワードそして変更するパスワードMicrosoft Excel でワークブックを作成している間。これらのパスワードを指定するために Excel が提供するインターフェース Microsoft を示すこのスクリーンショットを参照してください。
場合によっては、指定されたパスワードが一致するかどうかを確認する必要があります変更するパスワードプログラム的に。 Aspose.Cells提供[workbook.getSettings().getWriteProtection().validatePassword()](https://reference.aspose.com/cells/java/com.aspose.cells/writeprotection#validatePassword(java.lang.String))変更するために指定されたパスワードが正しいかどうかを確認するために使用できるメソッド。
Java 確認するコード Aspose.Cells を使用して変更するパスワード
次のサンプル コードは、ソースエクセルファイル。として開くためのパスワードがあります1234および変更するパスワード5678.コードは最初に以下をチェックします567変更する正しいパスワードであり、それが返されます間違いそして、それは5678変更するパスワードであり、それが返されます真実.
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CheckPassword.class) + "articles/"; | |
// Specify password to open inside the load options | |
LoadOptions opts = new LoadOptions(); | |
opts.setPassword("1234"); | |
// Open the source Excel file with load options | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx", opts); | |
// Check if 567 is Password to modify | |
boolean ret = workbook.getSettings().getWriteProtection().validatePassword("567"); | |
System.out.println("Is 567 correct Password to modify: " + ret); | |
// Check if 5678 is Password to modify | |
ret = workbook.getSettings().getWriteProtection().validatePassword("5678"); | |
System.out.println("Is 5678 correct Password to modify: " + ret); |
Java コードによって生成されたコンソール出力
上記のサンプル コードをロードした後のコンソール出力は次のとおりです。ソースエクセルファイル。
Is 567 correct Password to modify: false
Is 5678 correct Password to modify: true