将gridview 导入到excel

  
  private void Export(string FileType, string FileName)   

 {        Response.Charset = "GB2312";       

        Response.ContentEncoding = System.Text.Encoding.UTF7;      

  Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility - UrlEncode(FileName, Encoding.UTF8).ToString());       

 Response.ContentType = FileType;     

   this.EnableViewState = false;     

     StringWriter tw = new StringWriter();     

   HtmlTextWriter hw = new HtmlTextWriter(tw);      

  GridView1.RenderControl(hw);     

   Response.Write(tw.ToString());    

    Response.End();  

  }  



  protected void btngtoexcel_Click(object sender, EventArgs e)  

  {    

    ExpressionBinding("application/ms-excel", "ss.xls");   

    }    

public override void VerifyRenderingInServerForm(Control control) 

   {       

 base.VerifyRenderingInServerForm(control);  

  }

你可能感兴趣的:(String,object,Excel)