Open Different Microsoft Excel Versions Files
How to Open Files of Different Microsoft Excel Versions
An application often has to be able to open Microsoft Excel files created in different versions, for example, Microsoft Excel 95,97, or Microsoft Excel 2007/2010/2013/2016/2019 and Office 365 . You might need to load a file in any one of several formats, including XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited or TSV, CSV, ODS and so on. Use the constructor, or specify the Workbook class' FileFormat type attribute that specifies the format using the FileFormatType enumeration.
The FileFormatType enumeration contains many pre-defined file formats some of which are given below.
File Format Types | Description |
---|---|
Csv | Represents a CSV file |
Excel97To2003 | Represents an Excel 97 - 2003 file |
Xlsx | Represents an Excel 2007/2010/2013/2016/2019 and Office 365 XLSX file |
Xlsm | Represents an Excel 2007/2010/2013/2016/2019 and Office 365 XLSM file |
Xltx | Represents an Excel 2007/2010/2013/2016/2019 and Office 365 template XLTX file |
Xltm | Represents an Excel 2007/2010/2013/2016/2019 and Office 365 macro-enabled XLTM file |
Xlsb | Represents an Excel 2007/2010/2013/2016/2019 and Office 365 binary XLSB file |
SpreadsheetML | Represents a SpreadsheetML file |
Tsv | Represents a Tab-separated values file |
TabDelimited | Represents a Tab Delimited text file |
Ods | Represents an ODS file |
Html | Represents an HTML file |
Mhtml | Represents an MHTML file |
Open Microsoft Excel 95/5.0 Files
To open a Microsoft Excel 95/5.0 file, use LoadOptions and set the related attribute for the LoadOptions class for the template file to be loaded. A sample file for testing this feature can be downloaded from the following link:
// 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!"); | |
} |
Open Microsoft Excel 97 - 2003 Files
To open a Microsoft Excel 97 - 2003 file, use LoadOptions and set the related attribute for the LoadOptions class for the template file to be loaded.
// 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!"); | |
} |
Open Microsoft Excel 2007/2010/2013/2016/2019 and Office 365 XLSX Files
To open a Microsoft Excel 2007/2010/2013/2016/2019 and Office 365 format, that is, XLSX or XLSB, specify the file path. You can also use LoadOptions and set the related attribute/options of the LoadOptions class for the template file to be loaded.
// 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!"); |
Open Encrypted Excel Files
It’s possible to create encrypted Excel files using Microsoft Excel. To open an encrypted file, use the LoadOptions and set its attributes and options (for example, give a password) for the template file to be loaded. A sample file for testing this feature can be downloaded from the following link:
// 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 also supports opening password-protected Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365 files.