将SQL Server数据导出到.csv
时,波斯语中的短语无法正确显示。
string date = Helper.ToPersianDate(DateTime.Now).Replace("/", "");
date += ".csv";
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + date);
Response.ContentType = "text/csv";
Response.Charset = Encoding.Unicode.ToString();
foreach (DataRow r in ds.Tables[0].Rows)
{
Response.Write(r[0]);
Response.Write("\r\n");
}
Response.End();
答案 0 :(得分:0)
string date = Helper.ToPersianDate(DateTime.Now).Replace("/", "");
date += ".csv";
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + date);
Response.ContentType = "text/csv";
Response.Charset = Encoding.Unicode.ToString();
Response.ContentEncoding = System.Text.Encoding.Unicode;
/*
save utf-8 with BOM
GetPreamble
*/
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
foreach (DataRow r in ds.Tables[0].Rows)
{
Response.Write(r[0]);
Response.Write("\r\n");
}
Response.End();