ファイルフォーマットを検出してファイルが暗号化されているかどうかをチェックする方法
Contents
[
Hide
]
ファイルを直接読み取ることができない場合や、読み取るべきでない場合があるため、ファイルの形式を検出する必要があることがあります。Aspose.Cellsは、ドキュメントを処理するために使用できるFileFormatUtil.DetectFileFormat()静的メソッドと関連するAPIを提供しています。
次のサンプルコードは、ファイルパスを使用してファイルの形式を検出し、その拡張子をチェックし、ファイルが暗号化されているかどうかを判断する方法を示しています。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
//Detect file format | |
FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "Book1.xlsx"); | |
//Gets the detected load format | |
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat)); | |
//Check if the file is encrypted. | |
Console.WriteLine("The file is encrypted: " + info.IsEncrypted); |