1

A CSV file containing Japanese characters (UTF-8 characterset) is created from server-side using ASP.NET.

Code:

public void ExportToCsv_Click(object sender, EventArgs e)
    {
        try
        {
        string sContents = string.Empty;
        string sTemp;

        for (int k = 1; k <= (ObjList.Columns.Count - 1); k++)
        {
            sContents += ObjList.HeaderRow.Cells[k].Text + ",";
        }

        sContents += "\r\n";

        for (int i = 0; i <= (ObjList.Rows.Count - 1); i++)
        {
            for (int j = 1; j <= (ObjList.Columns.Count - 1); j++)
            {
                sTemp = (ObjList.Rows[i].Cells[j].Text.ToString());
                if (sTemp == "&nbsp;")
                    sTemp = "";
                if (j < ObjList.Columns.Count - 1)
                    sTemp = (sTemp + ",");
                sContents += sTemp;
            }
            sContents += "\r\n";
        }

        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();

        Response.AddHeader("Content-disposition", "attachment; filename=" + "partslist.csv");
        Response.ContentType = "application/csv";
        Response.Charset = "UTF-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8  ;

        Response.Write(sContents);
        Response.Flush();
        Response.End();
        }
        catch (Exception ex)
        {
    throw new Exception(ex.Message);
    }
    }

But, when this file is opened in Microsoft Excel 2003, it does not show file contents properly.

How to make excel to open such a file properly. Help will be appreciated.

Itz.Irshad
  • 914
  • 4
  • 22
  • 43

3 Answers3

1

Just add \xfeff at the beginning.

Racil Hilan
  • 22,887
  • 12
  • 43
  • 49
jack
  • 11
  • 1
0

Follow this procedure :

  • Menu -> Data -> GetExternal Data -> From Text
  • Select your csv using the file dialog
  • In the text import wizard, step 1, select "65001 : Unicode (UTF-8)" as file origin.
d-stroyer
  • 2,490
  • 2
  • 16
  • 31
0

Excel uses SJIS(Shift JIS) as default encoding.
You could try converting UTF-8 to SJIS or creating CSV file with BOM in UTF-8.
I was able to open UTF-8 csv file with BOM.

htnux
  • 63
  • 1
  • 8
  • I'm newbie to exporting CSV files. Can you tell me how to open UTF-8 CSV fiel with BOM. I mean, what to specify and where to specify ? – Itz.Irshad Jul 04 '13 at 10:04