ワークシートがパスワードで保護されているかどうかを検出する
Contents
[
Hide
]
ワークブックとワークシートを別々に保護することができます。たとえば、スプレッドシートには、パスワードで保護された 1 つ以上のワークシートが含まれている場合がありますが、スプレッドシート自体は保護されている場合とされていない場合があります。 Aspose.Cells API は、特定のワークシートがパスワードで保護されているかどうかを検出する手段を提供します。この記事では、Aspose.Cells for .NET API を使用して同じことを行う方法を示します。
Aspose.Cells for .NET 8.7.0 でProtection.IsProtectedWithPasswordワークシートがパスワードで保護されているかどうかを検出するプロパティ。ブール型Protection.IsProtectedWithPasswordプロパティリターン真実もしもワークシートパスワードで保護されており、間違いそうでない場合。
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-.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) | |
{ | |
Console.WriteLine("Worksheet is password protected"); | |
} | |
else | |
{ | |
Console.WriteLine("Worksheet is not password protected"); | |
} |