Why csv file doesnt show special characters in C#?

647 Views Asked by At

I have this code used on my application to convert xls file to csv file.

Excel.IExcelDataReader excelReader = Excel.ExcelReaderFactory.CreateBinaryReader(stream);
DataSet result = excelReader.AsDataSet();
excelReader.Close();
result.Tables[0].TableName.ToString();
string csvfile = "";
int row_no = 0;
int ind = 0;

while (row_no < result.Tables[ind].Rows.Count)
{
    for (int i = 0; i < result.Tables[ind].Columns.Count; i++)
    {
        csvfile += result.Tables[ind].Rows[row_no][i].ToString() + ",";
    }

    row_no++;
    csvfile += "\n";
}

output = System.Web.HttpContext.Current.Server.MapPath("/public/test.csv");
newOutput = Path.GetFileName(output);
StreamWriter csv = new StreamWriter(@output, false, Encoding.Unicode);
csv.Write(csvfile);
csv.Close();
csv.Dispose();

It worked fine but csv doesn't show cell values correctly. See below images and I have pasted my code as well. What can I change on this code to fix this?

This is the exported csv and it shows like this

enter image description here

I have tried replacing on my code, but I don't have changes

StreamWriter csv = new StreamWriter(@output, false, Encoding.ASCII);  
StreamWriter csv = new StreamWriter(@output, false, Encoding.Unicode);  
StreamWriter csv = new StreamWriter(@output, false, Encoding.GetEncoding("iso-8859-1")); 
0

There are 0 best solutions below