Aspose.Cellsを使用して変更用パスワードを確認する
Contents
[
Hide
]
与えられたパスワードが変更を許可のパスワードと一致するかどうかをプログラムでチェックする必要がある場合があります。Aspose.Cells は、与えられた変更を許可のパスワードが正しいかどうかをチェックするために使用できる WorkbookSettings.WriteProtection.ValidatePassword() メソッドを提供しています。
Microsoft Excelで変更するためのパスワードをチェックする
Microsoft Excelで作成するワークブックに開くためのパスワードおよび変更するためのパスワードを割り当てることができます。これらのパスワードを指定するためのMicrosoft Excelが提供するインターフェースを示すスクリーンショットをご覧ください。
![]() |
---|
Aspose.Cellsを使用して変更パスワードを確認する
次のサンプルコードは、元のExcelファイルをロードします。開くためのパスワードは1234であり、変更するためのパスワードは5678です。コードはまず、567が正しい変更するためのパスワードかどうかをチェックし、falseを返し、次に5678が変更するためのパスワードかどうかをチェックし、trueを返します。
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-.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); |
コンソール出力
上記のサンプルコードで元のExcelファイルをロードした後のコンソール出力はこちらです。
Is 567 correct Password to modify: False
Is 5678 correct Password to modify: True