打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
gridview输出流excel

  this.DataGrid1.Page.EnableViewState   =   false;
  System.IO.StringWriter     tw       =   new   System.IO.StringWriter();
  System.Web.UI.HtmlTextWriter   hw     =   new   System.Web.UI.HtmlTextWriter(tw);
  this.DataGrid1.RenderControl(hw);
  string   HtmlInfo   =   tw.ToString().Trim();

  string   DocFileName   =   "审批信息.xls ";
  string   FilePathName   =   Request.PhysicalPath;
  FilePathName     =   FilePathName.Substring(0,FilePathName.LastIndexOf( "\\ "));
  //得到Excel文件的物理地址
  FilePathName     =   FilePathName   + "\\ "   +   DocFileName;
  System.IO.File.Delete(FilePathName);  
  FileStream   Fs     =   new   FileStream(FilePathName,   FileMode.Create);
  BinaryWriter   BWriter=   new   BinaryWriter(Fs,System.Text.Encoding.GetEncoding( "GB18030 "));
  //将DataGrid的信息写入Excel文件
  BWriter.Write(HtmlInfo);
  BWriter.Close();
  Fs.Close();

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用 HttpWebRequest 下载任意类型的文件 HttpWebRequest Do...
ASP.NET Core Web API接收文件传输
asp.net(C#)检测真实文件类型-程序开发-红黑联盟
DataGridView控件中显示图片及其注意事项
C# 读取CSV文件
Java IO: PrintWriter
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服