怎么把 DataGrid里的数据 导入到 EXCEL 表里啊??
大家帮帮忙啊 !!

解决方案 »

  1.   

    private void Button1_Click(object sender, System.EventArgs e)
    {

    Response.ContentType="application/vnd.ms-excel";
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
    Response.AppendHeader("Content-Disposition","attachment;filename=teacher.xls");
    StringWriter tw=new StringWriter();
    HtmlTextWriter hw=new HtmlTextWriter(tw);
    DataGrid2.RenderControl(hw);
    //这里是要导出的对象,这里用的是DataGrid.也可以用别的控件;
    string filepath=Page.Server.MapPath("teacher.xls");
    StreamWriter sw=File.CreateText(filepath);
    sw.Write(tw.ToString());
    sw.Close();

    }
      

  2.   

    Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter w=new System.IO.StringWriter();
    System.Web.UI.Html32TextWriter html=new Html32TextWriter(w);

    this.DataGrid1.RenderControl(html);
    this.Response.Write(w.ToString());
    this.Response.End();
      

  3.   

    我的 DATAGRID 有分页   不行啊  不分页还好用 类型“DataGridLinkButton”的控件“dgExcel__ctl14__ctl1”必须放在具有 runat=server 的窗体标记内。 
      

  4.   

    sorrow_man(不会我就问,零下一度)QQ 上不了  只能用 MSN  你能上吗 ?