Opening Different Microsoft Excel Versions Files
Opening 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 use the Workbook class' setFileFormat method to 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 |
EXCEL_97_TO_2003 | 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 |
SPREADSHEET_ML | Represents a SpreadsheetML file |
TSV | Represents a Tab-separated values file |
TAB_DELIMITED | Represents a Tab Delimited text file |
ODS | Represents an ODS file |
HTML | Represents an HTML file |
M_HTML | Represents an MHTML file |
Opening 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:
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// Get the Excel file into stream | |
var fis = new FileInputStream("Excel95.xls"); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions options = new LoadOptions(LoadFormat.EXCEL_97_TO_2003); | |
// Create a Workbook object and opening the file from the stream | |
var workbook = new Workbook(fis, options); | |
System.out.println("Microsoft Excel 95/5.0 workbook opened successfully!"); |
Opening 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.
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// Get the Excel file into stream | |
var fis = new FileInputStream("Excel03.xls"); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions options = new LoadOptions(LoadFormat.EXCEL_97_TO_2003); | |
// Create a Workbook object and opening the file from the stream | |
var workbook = new Workbook(fis, options); | |
System.out.println("Microsoft Excel 97 - 2003 workbook opened successfully!"); |
Opening 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.
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// The path to the documents directory. | |
var dataDir = ""; | |
// Opening Microsoft Excel 2007 Xlsx Files | |
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.XLSX); | |
// Create a Workbook object and opening the file from its path | |
var wbExcel07 = new Workbook(dataDir + "Input.xlsx", loadOptions2); | |
System.out.println("Microsoft Excel 2007 - Office365 workbook opened successfully!"); |
Opening 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:
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// The path to the documents directory. | |
var dataDir = ""; | |
// Opening Microsoft Excel 2007 Xlsx Files | |
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.XLSX); | |
// Specify the password | |
loadOptions2.setPassword("1234"); | |
// Create a Workbook object and opening the file from its path | |
var wbEncrypted = new Workbook(dataDir + "EncryptedExcel.xlsx", loadOptions2); | |
System.out.println("Encrypted excel file opened successfully!"); |
Aspose.Cells also supports opening password-protected Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365 files.