Opening Files with Different Formats
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
To open a Microsoft Excel file using the file path, pass the path of the file as a parameter while creating the instance of the Workbook class. The following sample code demonstrates opening an Excel file using the file path.
Opening through Stream
Sometimes, the Excel file that you want to open is stored as a stream. In that case, similar to opening a file using the file path, pass the stream as a parameter while instantiating the Workbook class. The following sample code demonstrates opening an Excel file using stream.
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 the LoadOptions class to specify the format of the Excel file using the FileFormatType enumeration.
The FileFormatType enumeration contains many pre-defined file formats some of which are given below.
|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|
|TSV||Represents 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
Opening Microsoft Excel 97 Files
Opening Microsoft Excel 2000 Files
Opening Microsoft Excel 2003 Files
Opening Microsoft Excel XP Files
Opening Microsoft Excel 2007/2010 XLSX Files
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.
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 a tabular 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.
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.
Opening CSV files using preferred parser
This is not always necessary to use default parser settings for opening the CSV files. Sometimes importing CSV file does not create expected output like date format is not as expected or empty fields are handled differently. For this purpose TxtLoadOptions.PreferredParsers is available to provide own preferred parser to parse different data types as per the requirement. Following sample code demonstrates the usage of the preferred parser.
Sample source file and output files can be downloaded from the following links for testing this feature.
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.
Opening Tab-Separated Values (TSV) Files
TSV files are also used to contain spreadsheet data but without any formatting. The format is the same with Tab Delimited where data is arranged in rows and columns such as tables and spreadsheets.
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 as shown below in the example.
Aspose.Cells also supports opening password-protected MS Excel 2013 files.
Opening SXC Files
StarOffice Calc is similar to Microsoft Excel and supports formulas, charts, functions, and macros. The spreadsheets created with this software are saved with the SXC extension. The SXC file is also used for OpenOffice.org Calc spreadsheet files. Aspose.Cells can read SXC files as demonstrated by the following code sample.
Opening FODS Files
FODS file is spreadsheet saved in OpenDocument XML without any compression. Aspose.Cells can read FODS files as demonstrated by the following code sample.