Aspose.Cells を使用して変更するパスワードを確認してください

Java 確認するコード Aspose.Cells を使用して変更するパスワード

次のサンプル コードは、ソースエクセルファイル。として開くためのパスワードがあります1234および変更するパスワード5678.コードは最初に以下をチェックします567変更する正しいパスワードであり、それが返されます間違いそして、それは5678変更するパスワードであり、それが返されます真実.

// 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