ファイルフォーマットを検出してファイルが暗号化されているかどうかをチェックする方法
Contents
[
Hide
]
ファイルの拡張子だけでファイルの形式を特定することができないまたは直接読み込めない(パスワードで保護されている)場合、ファイルの形式を特定する必要があることがあります。Aspose.Cellsは、FileFormatUtil.detectFileFormat()静的メソッドおよびそれに関連するAPIを提供しており、これらを使用してドキュメントを処理することができます。
Javaコードでファイル形式を検出し、ファイルが暗号化されているかどうかをチェックする
次のサンプルコードは、ファイルパスを使用してファイルの形式を検出し、その拡張子をチェックし、ファイルが暗号化されているかどうかを判断する方法を示しています。
This file contains 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DetectFileFormatandCheckFileEncrypted.class); | |
// Detect file format | |
FileFormatInfo info = FileFormatUtil.detectFileFormat(dataDir + "Book1.xlsx"); | |
// Gets the detected load format | |
System.out.println("The spreadsheet format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat())); | |
// Check if the file is encrypted. | |
System.out.println("The file is encrypted: " + info.isEncrypted()); |