ASP.NET资料汇出Excel方法

原创 2006年06月08日 23:33:00

public class DataSetToExcel
 {
  public DataSetToExcel(){}
  public void Convert(DataSet oDS,HttpResponse Response)
  {
   Response.Clear();
   Response.Charset = "big5";
   Response.ContentType = "application/vnd.ms-excel";
   System.IO.StringWriter oSW = new System.IO.StringWriter();
   HtmlTextWriter oHW = new HtmlTextWriter(oSW);
   DataGrid oDG = new DataGrid();
   oDG.DataSource = oDS.Tables[0];
   oDG.DataBind();
   oDG.RenderControl(oHW);
   Response.Write(oSW.ToString());
   Response.Flush();
   Response.Close();
  }

  public void Convert(DataSet oDS,HttpResponse Response,string sCharSet)
  {
   Response.Clear();
   Response.Charset = sCharSet;
   Response.ContentType = "application/vnd.ms-excel";
   System.IO.StringWriter oSW = new System.IO.StringWriter();
   HtmlTextWriter oHW = new HtmlTextWriter(oSW);
   DataGrid oDG = new DataGrid();
   oDG.DataSource = oDS.Tables[0];
   oDG.DataBind();
   oDG.RenderControl(oHW);
   Response.Write(oSW.ToString());
   Response.Flush();
   Response.Close();
  }
 }

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ASP.NET资料汇出Excel方法
举报原因:
原因补充:

(最多只允许输入30个字)