关闭

ASP.NET资料汇出Excel方法

1004人阅读 评论(0) 收藏 举报

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();
  }
 }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:245966次
    • 积分:3583
    • 等级:
    • 排名:第9506名
    • 原创:102篇
    • 转载:2篇
    • 译文:0篇
    • 评论:97条
    文章分类
    最新评论