Su Sandar12
Su Sandar12

Reputation: 33

C#: Excel export doesn't show correctly for Myanmar Font data

I am trying to get datatable data as a CSV file. But the data with Myanmar font doesn't show correctly in excel. It is showing as the following character.

"လမ်း áႠလေးပုံá€á€•á€¯á€¶ မြို့" I attached my code.

DataTable dt = ToDataTable(objList);
        StringBuilder sb = new StringBuilder();

        IEnumerable<string> columnNames = dt.Columns.Cast<DataColumn>().
                                          Select(column => column.ColumnName);

        sb.AppendLine(string.Join(",", columnNames));

        foreach (DataRow row in dt.Rows)
        {
            IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
           
            sb.AppendLine(string.Join(",", fields));
        }
        string folderPath = HttpContext.Current.Server.MapPath("/Files") + "/Files/Export/";
        File.WriteAllText(folderPath + "Export.csv", sb.ToString());

Upvotes: 2

Views: 355

Answers (1)

Useme Alehosaini
Useme Alehosaini

Reputation: 3116

Replace

File.WriteAllText(folderPath + "Export.csv", sb.ToString());

With

File.WriteAllText(folderPath + "Export.csv", sb.ToString(), Encoding.Unicode);

According to https://www.unicode.org/faq/myanmar.html#:~:text=A%3A%20The%20Myanmar%20script%20was,extended%20the%20script%20in%202009.

The Myanmar script was added to the Unicode Standard in Version 3.0 (September, 1999). Version 5.2 significantly extended the script in 2009

Upvotes: 1

Related Questions