ファイルフォーマットを検出してファイルが暗号化されているかどうかをチェックする方法
Contents
[
Hide
]
時には、ファイルを開く前にフォーマットを検出する必要があります。ファイル拡張子だけでは内容が適している保証はなく、パスワード保護された暗号化ファイルは直接読めませんし、読むべきではありません。Aspose.Cells for Python via .NETは、FileFormatUtil.detect_file_format()の静的メソッドと関連APIを提供し、ドキュメントの処理に利用できます。
次のサンプルコードは、ファイルパスを使用してファイルの形式を検出し、その拡張子をチェックし、ファイルが暗号化されているかどうかを判断する方法を示しています。
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 FileFormatUtil | |
# 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(".") | |
# Detect file format | |
info = FileFormatUtil.detect_file_format(dataDir + "Book1.xlsx") | |
# Gets the detected load format | |
print("The spreadsheet format is: " + FileFormatUtil.load_format_to_extension(info.load_format)) | |
# Check if the file is encrypted. | |
print("The file is encrypted: " + str(info.is_encrypted)) |