谁有类似电子邮件里通讯录导入导出的代码,最好是c#的 ,支持xls,txt格式 ?

解决方案 »

  1.   

    if( this.EspeciallyInfo_Grid.Items.Count == 0 )
    {
    throw new Exception("没有数据不能导出!");
    } string filename="c:\\myexcel";
    //将datagrid内容导入到客户端excel文件 datagrid to excel
    int ss=EspeciallyInfo_Grid.Items.Count;
    this.Response.AddHeader("Content-Disposition",  "attachment; filename="+filename+".xls"); 
    this.Response.ContentType = "application/vnd.ms-excel"; 
    this.EnableViewState= true; 
    System.IO.StringWriter tw = new  System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter hw = new  System.Web.UI.HtmlTextWriter(tw); 
    EspeciallyInfo_Grid.RenderControl(hw); 
    this.Response.Write(tw.ToString()); 
    Response.End();