我試圖SQL Server表導出到一個CSV文件:CSV文件導出問題
表中數據是像= PRESENTACION或彌散
所有的工作好...但在.CSV
文件我發現:
Presentación or Difusión
這是我的.cs代碼:
GridView1.AllowPaging = false;
GridView1.DataBind();
StringBuilder sb = new StringBuilder();
for (int k = 0; k < GridView1.Columns.Count; k++)
{
// add separator
sb.Append(GridView1.Columns[k].HeaderText + ';');
}
// append new line
sb.Append("\r\n");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
for (int k = 0; k < GridView1.Columns.Count; k++)
{
// add separator
sb.Append(GridView1.Rows[i].Cells[k].Text + ';');
}
// append new line
sb.Append("\r\n");
}
Encoding encoding = Encoding.UTF8;
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=OrigenDatos.csv");
Response.Charset = encoding.EncodingName;
Response.ContentType = "application/text";
Response.ContentEncoding = Encoding.Unicode;
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
UTF-8是真正的字符集嗎?
UTF是一個字符集,但你的文字無疑是utf與HTML編碼。 –
utf-8被指定在我的webform.aspx @MarcB – Synapsido
看看我的答案。更多信息可以在這裏找到:https://www.w3.org/TR/html401/charset.html#h-5.2.2 –