異なるMicrosoft Excelバージョンのファイルを開く

異なるMicrosoft Excelバージョンのファイルを開く方法

アプリケーションは、たとえばMicrosoft Excel 95、97、Microsoft Excel 2007/2010/2013/2016/2019、およびOffice 365で作成されたMicrosoft Excelファイルを開くことができる必要があります。さまざまな形式のファイル、XLS、XLSX、XLSM、XLSB、SpreadsheetML、タブ区切りやTSV、CSV、ODSなどのいずれかの形式でファイルを読み込む必要があるかもしれません。コンストラクタを使用するか、WorkbookクラスのFileFormat属性を指定して、FileFormatType列挙型を使用してフォーマットを指定します。

FileFormatType列挙型には、多くの事前定義ファイル形式が含まれています。 以下にその一部を示します。

ファイルの形式の種類 説明
Csv はCSVファイルを表します
Excel97To2003 はExcel 97-2003ファイルを表します
Xlsx はExcel 2007/2010/2013/2016/2019およびOffice 365 XLSXファイルを表します
Xlsm はExcel 2007/2010/2013/2016/2019およびOffice 365 XLSMファイルを表します
Xltx はExcel 2007/2010/2013/2016/2019およびOffice 365テンプレートXLTXファイルを表します
Xltm はExcel 2007/2010/2013/2016/2019およびOffice 365マクロ有効なXLTMファイルを表します
Xlsb はExcel 2007/2010/2013/2016/2019およびOffice 365バイナリXLSBファイルを表します
SpreadsheetML はSpreadsheetMLファイルを表します
Tsv はタブ区切りの値ファイルを表します
TabDelimited はタブ区切りのテキストファイルを表します
Ods はODSファイルを表します
Html はHTMLファイルを表します
Mhtml はMHTMLファイルを表します

Microsoft Excel 95/5.0ファイルを開く

Microsoft Excel 95/5.0 ファイルを開くには、LoadOptions を使用し、読み込むテンプレートファイルの関連属性を LoadOptions クラスに設定します。この機能のテスト用のサンプルファイルは、次のリンクからダウンロードできます:

Excel95 File

// 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);
// Get the Excel file into stream
using (FileStream stream = new FileStream(dataDir + "Excel95_5.0.xls", FileMode.Open))
{
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
Workbook wbExcel95 = new Workbook(stream, loadOptions1);
Console.WriteLine("Microsoft Excel 95/5.0 workbook opened successfully!");
}

Microsoft Excel 97-2003ファイルを開く

Microsoft Excel 97 - 2003 ファイルを開くには、LoadOptions を使用し、読み込むテンプレートファイルの関連属性を LoadOptions クラスに設定します。

// 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);
// Get the Excel file into stream
using (FileStream stream = new FileStream(dataDir + "Book_Excel97_2003.xls", FileMode.Open))
{
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
Workbook wbExcel97 = new Workbook(stream, loadOptions1);
Console.WriteLine("Microsoft Excel 97 - 2003 workbook opened successfully!");
}

Microsoft Excel 2007/2010/2013/2016/2019およびOffice 365 XLSXファイルを開く

Microsoft Excel 2007/2010/2013/2016/2019 および Office 365 形式、つまり XLSX または XLSB を開くには、ファイルパスを指定します。また、 LoadOptions を使用し、テンプレートファイルの関連属性/オプションを読み込む LoadOptions クラスに設定できます。

// 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);
// Opening Microsoft Excel 2007 Xlsx Files
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.Xlsx);
// Create a Workbook object and opening the file from its path
Workbook wbExcel2007 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2);
Console.WriteLine("Microsoft Excel 2007 - Office365 workbook opened successfully!");

暗号化されたExcelファイルを開く

Microsoft Excelで暗号化されたファイルを作成することは可能です。暗号化されたファイルを開くには、LoadOptionsを使用し、テンプレートファイルの属性とオプション(たとえばパスワードを指定)を設定します。 この機能のテスト用のサンプルファイルは、以下のリンクからダウンロードできます:

Encrypted Excel

// 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);
// Instantiate LoadOptions
LoadOptions loadOptions6 = new LoadOptions();
// Specify the password
loadOptions6.Password = "1234";
// Create a Workbook object and opening the file from its path
Workbook wbEncrypted = new Workbook(dataDir + "encryptedBook.xls", loadOptions6);
Console.WriteLine("Encrypted excel file opened successfully!");

Aspose.Cells は、パスワードで保護された Microsoft Excel 2007 年、2010 年、2013 年、2016 年、2019 年、Office 365 ファイルを開くこともサポートしています。