如何设置 编码格式 使生成的csv文件 是 utf8 带 BOM的 代码附上

wojiaonimabi 2016-03-07 10:34:16
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer = False
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive")
HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary")
HttpContext.Current.Response.ContentType = "application/octet-stream;charset=UTF-8"
HttpContext.Current.Response.Charset = "UTF-8"
'HttpContext.Current.Response.HeaderEncoding = Encoding.GetEncoding("Shift-JIS")
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
' HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("goods.csv"))
...全文
989 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qbilbo 2016-03-07
  • 打赏
  • 举报
回复
Dim strCsv As String = "....." 'csv文件内容 Dim bs() As Byte = System.Text.Encoding.UTF8.GetBytes(strCsv) Dim bom() As Byte = {&HEF, &HBB, &HBF} Dim data(bs.Length + 2) As Byte Array.Copy(bom, data, 3) Array.Copy(bs, 0, data, 3, bs.Length) HttpContext.Current.Response.BinaryWrite(data)
wojiaonimabi 2016-03-07
  • 打赏
  • 举报
回复
手动往文件开头加上 BOM头就可以了。 OK 结了

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧