Opening Files with Different Formats

Opening Files with Different Formats

Aspose.Cells allows developers to open spreadsheet files with different formats such as SpreadsheetML, Comma-separated values (CSV), tab-delimited or Tab-separated values (TSV), and ODS 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 XML representations of spreadsheets including all information about it, such as formatting, formulae, etc. Since Microsoft Excel XP, an XML export option has been added to Microsoft Excel that exports your spreadsheets to SpreadsheetML files.

loadOptions, _ := NewLoadOptions(LoadFormat_Xml)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.xml", loadOptions)

Opening HTML Files

Aspose.Cells allows you to open HTML file into Workbook object. The HTML file should Microsoft Excel oriented i.e MS-Excel should be able to open it.

loadOptions, _ := NewLoadOptions(LoadFormat_Html)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.html", loadOptions)

Opening CSV Files

Comma Separated Values (CSV) files contain records where the values are separated by commas. Data is stored as a table where each column is separated by the comma character and quoted by the double quote character. If a field value contains a double quote character it is escaped with a pair of double quote characters. You can also use Microsoft Excel to export spreadsheet data to CSV.

loadOptions, _ := NewLoadOptions(LoadFormat_Csv)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.cvs", loadOptions)

Opening Text Files with Custom Separator

Text files are used to hold spreadsheet data without formatting. The file is a kind of plain text file that can have some customized delimiters.

txtLoadOptions, _ := NewTxtLoadOptions()
txtLoadOptions.SetSeparator(',')
txtLoadOptions.SetEncoding(EncodingType_UTF8)
workbook, _ := NewWorkbook_String_LoadOptions("CustomSeparator.txt", txtLoadOptions.ToLoadOptions())
workbook.Save_String("CustomSeparator.xlsx")

Sample source files can be downloaded from the following links for testing this feature.

CustomSeparator.txt

Opening Tab Delimited Files

Tab delimited (Text) file contains spreadsheet data but without any formatting. Data is arranged in rows and columns like in tables and spreadsheets. Basically, a tab-delimited file is a special kind of plain text file with a tab between each column.

loadOptions, _ := NewLoadOptions(LoadFormat_TabDelimited)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.txt", loadOptions)

Opening Tab-Separated Values (TSV) Files

A tab-separated values (TSV) file contains spreadsheet data but without any formatting. It is the same with a tab-delimited file where data is arranged in rows and columns like in tables and spreadsheets.

loadOptions, _ := NewLoadOptions(LoadFormat_Tsv)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.tsv", loadOptions)

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.

loadOptions, _ := NewLoadOptions(LoadFormat_Sxc)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.sxc", loadOptions)

Opening FODS Files

FODS file is a spreadsheet saved in OpenDocument XML without any compression. Aspose.Cells can read FODS files, as demonstrated by the following code sample.

loadOptions, _ := NewLoadOptions(LoadFormat_Fods)
workbook, _ := NewWorkbook_String_LoadOptions("Book1.fods", loadOptions)