ワークシートの保護に使用するパスワードの確認
Contents
[
Hide
]
Aspose.Cells API により、保護いくつかの便利なプロパティとメソッドを導入してクラスを作成します。そのような方法の 1 つは、パスワードを照合しますこれにより、パスワードをインスタンスとして指定できますストリングを保護するために同じパスワードが使用されているかどうかを確認します。ワークシート.
のProtection.VerifyPasswordメソッドが返す真実指定されたパスワードが、指定されたワークシートを保護するために使用されるパスワードと一致する場合、および間違い指定したパスワードが一致しない場合。次のコードでは、Protection.VerifyPasswordと組み合わせた方法Protection.IsProtectedWithPasswordプロパティを使用してパスワード保護を検出し、パスワードを検証します。
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); | |
// Create an instance of Workbook and load a spreadsheet | |
var book = new Workbook(dataDir + "Sample.xlsx"); | |
// Access the protected Worksheet | |
var sheet = book.Worksheets[0]; | |
// Check if Worksheet is password protected | |
if (sheet.Protection.IsProtectedWithPassword) | |
{ | |
// Verify the password used to protect the Worksheet | |
if (sheet.Protection.VerifyPassword("1234")) | |
{ | |
Console.WriteLine("Specified password has matched"); | |
} | |
else | |
{ | |
Console.WriteLine("Specified password has not matched"); | |
} | |
} |