Convert CSV, TSV and TXT to Excel

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.

Opening CSV files and replacing invalid characters

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

Using preferred parser

It is not always necessary to use the default parser settings when opening CSV files. Sometimes importing a CSV file does not create the expected output, such as the date format being incorrect or empty fields being handled differently. For this purpose, TxtLoadOptions.PreferredParsers is available to provide a custom parser to parse different data types as required. The 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.

samplePreferredParser.csv

outputsamplePreferredParser.xlsx

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.

Opening Tab Delimited Files

A 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.

Opening Tab-Separated Values (TSV) Files

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

Advanced topics