Aspose.Cells for Python via .NETを使った編集用パスワードの確認

Microsoft Excelで変更するためのパスワードをチェックする

Microsoft Excelで作成するワークブックに開くためのパスワードおよび変更するためのパスワードを割り当てることができます。これらのパスワードを指定するためのMicrosoft Excelが提供するインターフェースを示すスクリーンショットをご覧ください。

todo:image_alt_text

Aspose.Cells for Python via .NETを使った変更用パスワードの確認

次のサンプルコードは、元のExcelファイルをロードします。開くためのパスワードは1234であり、変更するためのパスワードは5678です。コードはまず、567が正しい変更するためのパスワードかどうかをチェックし、falseを返し、次に5678が変更するためのパスワードかどうかをチェックし、trueを返します。

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