Reading CSV File with Multiple Encodings

Aspose.Cells provides the TxtLoadOptions.IsMultiEncoded property, which you need to set to true to load your CSV file with multiple encodings properly.

The following screenshot shows a sample CSV file that contains two lines. The first line is in ANSI encoding and the second line is in Unicode encoding

Input file
todo:image_alt_text

The following screenshot shows the XLSX file converted from the above CSV file without setting the TxtLoadOptions.IsMultiEncoded property to true. As you can see, the Unicode text was not converted properly.

Output file 1: no accommodation made for multiple encoding
todo:image_alt_text

The following screenshot shows the XSLX file converted from the above CSV file after setting the TxtLoadOptions.IsMultiEncoded property to true. As you can see, the Unicode text is now converted properly.

Output file 2: IsMultiEncoded is set to true
todo:image_alt_text

Below is the sample code that converts the above CSV file into XLSX format properly.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string filePath = dataDir + "MultiEncoded.csv";
// Set Multi Encoded Property to True
TxtLoadOptions options = new TxtLoadOptions();
options.IsMultiEncoded = true;
// Load the CSV file into Workbook
Workbook workbook = new Workbook(filePath, options);
// Save it in XLSX format
workbook.Save( filePath + ".out.xlsx", SaveFormat.Xlsx);
  • Opening CSV Files