Skip to end of metadata
Go to start of metadata

Developers use of Aspose.Cells to open files for different purposes. For example, open a file to retrieve data from it, or use a pre-defined designer spreadsheet file to speed up your development process. Aspose.Cells allows developers to open different kinds of source files. These source files can be Microsoft Excel reports, SpreadsheetML, Comma-separated values (CSV), Tab Delimited or Tab-separated values (TSV) files. This article discusses opening these different source files using Aspose.Cells.

 

Simple Ways to Open Excel Files

Important to Know

Aspose.Cells supports Excel file formats from Excel 97 to Excel 2007/2010. But, if you save your Excel file in the following format as shown below in the figure then your Excel file will fail to open using Aspose.Cells.

Don't save your Excel files in this format

If you do, the Excel file will contain data in Excel 5.0/95 format, which is not supported by Aspose.Cells. So, please save your Excel file as a Microsoft Excel Workbook as shown below.

Save your Excel files in this format

Opening through Path

Simply open a Microsoft Excel file by referencing the file's path by calling the LoadOptions method of the Workbook class. All you have to do, is to pass the file path to the LoadOptions method as shown below.

Example

Opening through Stream

Sometimes, the Excel file that you want to open is stored as a stream. In that case, use an overloaded version of the Open method that takes the Stream object that contains the Excel file to open the file.

Example

Opening Files of Different Microsoft Excel Versions

It's very common to believe that the Excel files that you're opening could be created by different versions of Microsoft Excel: Microsoft Excel 97, 2000, XP, 2003 and 2007/2010. When that's the case, use another overloaded Open method that not only takes the file – through a file path or as a stream – but also allows you to specify the format of the Excel file using the FileFormatType enumeration.

The FileFormatType enumeration contains many pre-defined file formats (that can be chosen by you) as follows:

File Format Types

Description

AsposePdf

Specifies the spreadsheet in Aspose.Pdf.Xml format that can be read by Aspose.Pdf to produce a PDF file.

CSV

Represents a CSV file

Default

Represents an Excel 2003 file

Excel97

Represents an Excel 97 file

Excel2000

Represents an Excel 2000 file

ExcelXP

Represents an Excel XP file

Excel2003

Represents an Excel 2003 file

Excel2007Xlsx

Represents an Excel 2007 xlsx file

Excel2007Xlsm

Represents an Excel 2007 xlsm file

Excel2007Xltx

Represents an Excel 2007 template xltx file

Excel2007Xltm

Represents an Excel 2007 macro-enabled xltm file

Excel2007Xlsb

Represents an Excel 2007 binary xlsb file

SpreadsheetML

Represents a SpreadSheetML file

TSVRepresents a Tab-separated values file

TabDelimited

Represents a Tab Delimited text file

HTML

Represents an html file(s)

MHTML

Represents an MHtml file(s)

ODS

Represents an OpenDocument Spreadsheet file

Opening Microsoft Excel 95/5.0 Files

To open Microsoft Excel 95 files, call the LoadOptions method and select the Auto value, pre-defined in the FileFormatType enumeration. Sample file to test the code can be downloaded from the following link:

Excel95_5.0.xls

Example
// Opening Microsoft Excel 95 Files
// Creating an EXCEL_95 LoadOptions object
LoadOptions loadOptions1 = new LoadOptions(FileFormatType.EXCEL_95);
 
// Creating an Workbook object with excel 95 file path and the
// loadOptions object
new Workbook(srcDir + "Excel95_5.0.xls", loadOptions1); 

Opening Microsoft Excel 97 Files

To open Microsoft Excel 97 files, call the LoadOptions method and select the EXCEL97 value, pre-defined in the FileFormatType enumeration.

Example

Opening Microsoft Excel 2000 Files

To open Microsoft Excel 2000 files, call the LoadOptions method and select the EXCEL2000 value, predefined in the FileFormatType enumeration.

Example

Opening Microsoft Excel 2003 Files

To open Microsoft Excel 2003 files, call the LoadOptions method and select the EXCEL2003 value, predefined in the FileFormatType enumeration.

Example

Opening Microsoft Excel XP Files

To open Microsoft Excel XP files, call the LoadOptions method and select the EXCELlXP value, predefined in the FileFormatType enumeration.

Example

Opening Microsoft Excel 2007/2010 XLSX Files

To open Microsoft Excel 2007/2010 XLSX files, call the LoadOptions method and select the EXCEL2007 value, predefined in the FileFormatType enumeration.

Example

Opening Files with Different Formats

Aspose.Cells allows developers to open spreadsheet files with different formats such as SpreadsheetML, CSV, Tab Delimited files. To open such files, developers can use the same methodology as they use for opening files of different Microsoft Excel versions.

Opening SpreadsheetML Files

SpreadsheetML files are the XML representations of your spreadsheets including all information about the spreadsheet such as formatting, formulae etc. Since Microsoft Excel XP, an XML export option is added to Microsoft Excel that exports your spreadsheets to SpreadsheetML files.

To open SpreadsheetML files, call LoadOptions method and select the SPREADSHEETML value, predefined in the FileFormatType enumeration.

Example

Opening CSV Files

Comma Separated Values (CSV) files contain records whose values are delimited or separated by commas. In CSV files, data is stored in tablular format that has fields separated by the comma character and quoted by the double quote character. If a field's value contains a double quote character it is escaped with a pair of double quote characters. You can also use Microsoft Excel to export your spreadsheet data to a CSV file.

To open CSV files, call LoadOptions method and select the CSV value, predefined in the FileFormatType enumeration.

Example

Opening CSV files and replacing invalid characters

In Excel, when CSV file with special characters is opened, the characters are automatically replaced. The same is done by Aspose.Cells API which is demonstrated in the code example given below.

Example

Opening Tab Delimited Files

Tab delimited files contain spreadsheet data but without any formatting. Data is arranged in rows and columns such as tables and spreadsheets. Shortly, a tab delimited file is a special kind of plain text file with a tab between each column in the text.

To open tab delimited files, developers should call the LoadOptions method and select the TAB_DELIMITED value, predefined in the FileFormatType enumeration.

Example

Opening Tab-Separated Values (TSV) Files

TSV files are also used to contain spreadsheet data but without any formatting. The format is same with Tab Delimited where data is arranged in rows and columns such as tables and spreadsheets.

To open tab delimited files, developers should call the LoadOptions method and select the TSV value, predefined in the FileFormatType enumeration.

Example

 

Java

 

Opening Encrypted Excel Files

We know that it's possible to create encrypted Excel files using Microsoft Excel. To open such encrypted files, developers should call a special overloaded LoadOptions method and select the DEFAULT value, predefined in the FileFormatType enumeration. This method would also take the password for the encrypted file a shown below in the example.

Example


Aspose.Cells also supports opening password protected MS Excel 2013 files.

There are fair chances that the Workbook constructor may throw System.OutOfMemoryException while loading large spreadsheets. This exception suggests that the available memory is insufficient to completely load the spreadsheet into the memory therefore the spreadsheet has to be loaded while enabling the Memory Preferences.

Labels
  • No labels