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