Free Support Forum - aspose.com

Issue to Convet CSV and Exxel Sheet For special charactors


#1

I am converting CSV and Excel sheet file to C# datatable
The string “René” is converting to “Ren�” which is wrong.

Code

LoadOptions loadOptions = new LoadOptions(LoadFormat.Auto);
if (extension.ToLower().Contains(“csv”))
loadOptions = new LoadOptions(LoadFormat.CSV);
Workbook workbook = new Workbook(stream, loadOptions);
Worksheet worksheet = workbook.Worksheets[0];
var datatable = new DataTable()
if (extension.ToLower().Contains(“csv”))
dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.MaxColumn + 1, options: new ExportTableOptions { ExportAsString = true });
else
dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.Rows.Count, worksheet.Cells.MaxColumn + 1);

Thanks
Mahesh


#2

@bhosalemahesh899,

Thanks for the code segment and details.

Could you provide us template CSV file, we will check it soon.


#3

Please set the encoding of the stream ,see following codes:
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.Encoding = Encoding.Unicode;//set excepted encoding.

        Workbook workbook = new Workbook(stream, loadOptions);