首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net 导出有关问题

2012-10-20 
vb.net 导出问题Response.Clear()Response.Buffer TrueResponse.Charset GB2312Response.AppendHead

vb.net 导出问题
Response.Clear()
  Response.Buffer = True
  Response.Charset = "GB2312"
  Response.AppendHeader("Content-Disposition", "attachment;filename=001.xls")
  Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
  Response.ContentType = "application/excel"
  Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
  Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
  GridView1.RenderControl(oHtmlTextWriter)
  Response.Output.Write(oStringWriter.ToString())
  Response.Flush()
  Response.End() 
为什么导出来的 没有任何数据 一片空白 ?oStringWriter 这里面有值 但是excel显示 就没任何数据

[解决办法]
没有传送数据的亲

C# code
/*          using System.IO;         */         string fileName = "asd.txt";//客户端保存的文件名          string filePath = Server.MapPath("DownLoad/aaa.txt");//路径         FileInfo fileInfo = new FileInfo(filePath);         Response.Clear();         Response.ClearContent();         Response.ClearHeaders();         Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);         Response.AddHeader("Content-Length", fileInfo.Length.ToString());         Response.AddHeader("Content-Transfer-Encoding", "binary");         Response.ContentType = "application/octet-stream";         Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");// 这里是你要下载的文件路径         Response.WriteFile(fileInfo.FullName);         Response.Flush();         Response.End(); 

热点排行