Reputation: 1024
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 == " ")
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.
Upvotes: 1
Views: 1580
Reputation: 63
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.
Upvotes: 0
Reputation: 2706
Follow this procedure :
Upvotes: 0