0
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "iso-8859-9";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;

//open file
StreamWriter wr = new StreamWriter(@"D:\\book.xls");

for (int i = 0; i < dt.Columns.Count; i++)
{
    wr.Write(string.Format(new CultureInfo("tr-TR"),dt.Columns[i].ToString().ToUpper() + "\t"));
}

wr.WriteLine();

//write rows to excel file
for (int i = 0; i < (dt.Rows.Count); i++)
{
    for (int j = 0; j < dt.Columns.Count; j++)
    {
        if (dt.Rows[i][j] != null)
        {
            wr.Write(string.Format(new CultureInfo("tr-TR"), Convert.ToString(dt.Rows[i][j]) + "\t"));
        }
        else
        {
            wr.Write("\t");
        }
    }

    //go to next line
    wr.WriteLine();
}
//close file
wr.Close();

My problem is EĞİTİM is automatically changed to EÄİTİM when exporting to Excel.

ekad
  • 14,436
  • 26
  • 44
  • 46
Eren Tur
  • 66
  • 1
  • 5
  • what is your problem? I think your encoding is wrong. –  Sep 13 '16 at 06:57
  • Possible duplicate of [How to add encoding information to the response stream in ASP.NET?](http://stackoverflow.com/questions/1005530/how-to-add-encoding-information-to-the-response-stream-in-asp-net) –  Sep 13 '16 at 07:00

1 Answers1

2

This answer is from here How to add encoding info

I think the problem is with Excel based on Microsoft Excel mangles Diacritics in .csv files. To prove this, copy your sample output string of ąęćżźńółĄŚŻŹĆŃŁÓĘ and paste into a test file using your favorite editor, and save as a UTF-8 encoded .csv file. Open in Excel and see the same issues.

Community
  • 1
  • 1