Opening CSV with é character

I have a CSV, ANSI encoded, with the é character in it. When I open it from Aspose, it messes up that character.


var wb = new Aspose.Cells.Workbook(@“C:\funny.csv”);
var ce = wb.Worksheets[0].Cells[0, 0]; // The é character is bad

Obviously this is an encoding thing. But the file is Windows ANSI encoded (attached), not UTF8 and not UNICODE.

How do I open this type of file?

Thanks

Hi,

Thanks for your posting and using Aspose.Cells.

Please set the TxtLoadOptions.IsMultiEncoded property to true before loading your csv file. Please download and use the latest version: Aspose.Cells
for .NET v8.2.0.1
for this.

Please see the following code and its output for your reference.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\funny.csv”;


TxtLoadOptions options = new TxtLoadOptions();

options.IsMultiEncoded = true;


Workbook workbook = new Workbook(filePath, options);


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“A1”];


Debug.WriteLine(cell.StringValue);

Debug Output:
Cédric

thanks. That works for that particular CSV. But if I set that for an XLSX (for instance) with the same character, it returns bad data.


What exactly does that flag do and why is it needed since the character is a standard character?

Hi,

Thanks for your posting and using Aspose.Cells.

TxtLoadOptions.IsMultiEncoded property is used when there are multiple encodings inside the CSV file, for example, when there is Ansi, Unicode etc.

For XLSX, we did not notice any issue, the character displays well. Please see the following screenshot for a reference.

However, we have logged this issue in our database for investigation to see if this character could be read fine without setting the IsMultiEncoded property. We will look into it and let you, if it needs to be fixed, we will fix it.

This issue has been logged as CELLSNET-42952.

Hi,

Thanks for using Aspose.Cells.

We have evaluated this issue further. It is actually encoding issue. If you use Windows-1252 or UTF-7 encoding, it will work fine. You do not now need to use TxtLoadOptions.IsMultiEncoded property.

C#


TxtLoadOptions opts = new TxtLoadOptions();

//Use this one

opts.Encoding = Encoding.GetEncoding(“Windows-1252”);


//Or use this one

opts.Encoding = Encoding.GetEncoding(“UTF-7”);


Workbook wb = new Workbook(“funny.csv”, opts);


Cell cell = wb.Worksheets[0].Cells[“A1”];

Thanks, that works better.


What is the default encoding if that is not specified?

Hi,

Thanks for your posting and using Aspose.Cells.

The default encoding might change from system to system. In my computer, the default encoding is same as Encoding.GetEncoding(“Windows-1252”), therefore the following code works fine at my end.

Please try it at your end and see how it goes at your side.

C#


TxtLoadOptions opts = new TxtLoadOptions();


Workbook wb = new Workbook(“funny.csv”, opts);


Cell cell = wb.Worksheets[0].Cells[“A1”];


You can also check the default encoding of your system using the following code.

C#
Console.WriteLine(Encoding.Default);