Aspose.Cells for Python via .NETを使った編集用パスワードの確認
Contents
[
Hide
]
時には、プログラム側で与えられたパスワードが変更用パスワードと一致するかどうかを確認する必要があります。Aspose.Cells for Python via .NETは、WorkbookSettings.write_protection.validate_password()メソッドを提供し、変更用パスワードの正誤を確認できます。
Microsoft Excelで変更するためのパスワードをチェックする
Microsoft Excelで作成するワークブックに開くためのパスワードおよび変更するためのパスワードを割り当てることができます。これらのパスワードを指定するためのMicrosoft Excelが提供するインターフェースを示すスクリーンショットをご覧ください。
![]() |
---|
Aspose.Cells for Python via .NETを使った変更用パスワードの確認
次のサンプルコードは、元のExcelファイルをロードします。開くためのパスワードは1234であり、変更するためのパスワードは5678です。コードはまず、567が正しい変更するためのパスワードかどうかをチェックし、falseを返し、次に5678が変更するためのパスワードかどうかをチェックし、trueを返します。
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 LoadOptions, 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(".") | |
# Specify password to open inside the load options | |
opts = LoadOptions() | |
opts.password = "1234" | |
# Open the source Excel file with load options | |
workbook = Workbook(dataDir + "sampleBook.xlsx", opts) | |
# Check if 567 is Password to modify | |
ret = workbook.settings.write_protection.validate_password("567") | |
print("Is 567 correct Password to modify: " + str(ret)) | |
# Check if 5679 is Password to modify | |
ret = workbook.settings.write_protection.validate_password("5678") | |
print("Is 5678 correct Password to modify: " + str(ret)) |
コンソール出力
上記のサンプルコードで元のExcelファイルをロードした後のコンソール出力はこちらです。
Is 567 correct Password to modify: False
Is 5678 correct Password to modify: True