ワークシートがパスワードで保護されているかどうかを検出する
Contents
[
Hide
]
ワークブックおよびワークシートは個別に保護可能です。例えば、スプレッドシートにはパスワード保護された複数のワークシートが含まれる場合もありますが、スプレッドシート自体は保護されていない場合もあります。Aspose.Cells for Python via .NET APIは、特定のワークシートがパスワード保護されているかどうかを検出する手段を提供します。この資料では、その使用方法について説明します。
Aspose.Cells for Python via .NETは、Protection.is_protected_with_password プロパティを公開しており、これによりワークシートがパスワード保護されているかどうかを確認できます。Boolean型の Protection.is_protected_with_password プロパティは、ワークシートがパスワード保護されていればtrueを返し、そうでなければfalseを返します。
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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create an instance of Workbook and load a spreadsheet | |
book = Workbook(dataDir + "sample.xlsx") | |
# Access the protected Worksheet | |
sheet = book.worksheets[0] | |
# Check if Worksheet is password protected | |
if sheet.protection.is_protected_with_password: | |
print("Worksheet is password protected") | |
else: | |
print("Worksheet is not password protected") |