http://expert.csdn.net/Expert/topic/1604/1604105.xml?temp=.669552

解决方案 »

  1.   

    不懂你的意思。导出这个过程是Web 实现的?? 那咋来后台进程??还是有个后台进程,这个进程访问个有DataGrid的页面,然后把其中DataGrid中的数据导出到Excel ??
      

  2.   

    导出到excel时,打开execl文件,服务器后台应该有一个excel.exe进程,据说很难将他shutdown掉,自己顶一下。up!
      

  3.   

    Excel.Application.DisplayAlert = false
    Excel.Application.Quit
    foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) 
    {
    if(p.ProcessName.ToUpper() == "EXCEL")
    {
    p.Kill();
    }
    }
      

  4.   

    关于Excel的导入导出:我是这样导出Excel的。
    //导出到EXCEL的函数
    public void ToExcel(System.Web.UI.Control ctl)  
    {
    HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.txt");
    HttpContext.Current.Response.Charset = "gb2312";
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
    HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
    // HttpContext.Current.Response.ContentType ="application/Microsoft Excel";
    // ctl.Page.EnableViewState = false;
    System.IO.StringWriter tw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
    ctl.RenderControl(hw);
    HttpContext.Current.Response.Write(tw.ToString());
    HttpContext.Current.Response.End();
    ctl.Visible = false;
    }
    但是我用这种方法导出的EXCEL表不能导入。导入的方法:
         private void BindExcel(string Excel_File_Name)
    {
    string My_ExeclConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + 
    "Data Source=" + Excel_File_Name + ";" + 
    "Extended Properties='Excel 8.0;HDR=YES;'" ;
    string My_ExeclComm_Str = "Select * From [Sheet2$]";
    OleDbDataAdapter My_ExeclAdapter = new OleDbDataAdapter(My_ExeclComm_Str, My_ExeclConn);
    DataSet My_ExeclDataSet = new DataSet(); //Fill方法将数据从数据源复制到DataSet中
    My_ExeclAdapter.Fill(My_ExeclDataSet);
    Excel_DataGrid.DataSource = My_ExeclDataSet;
    // Excel_DataGrid.DataMember = "Excel";
    Excel_DataGrid.DataBind();

    }
    请大侠救命,感激不尽。感激不尽答:
    用这个方法做出的Excel表是网页形式,是用MS—EXCEL强制打开的。本身是个网页。所以要打开这个。XLS文件,需要:
    C_Act Use_Act = new C_Act();
    Excel.Application myExcel = new Excel.Application();
    Object oMissing=System.Reflection.Missing.Value;
    Excel.Workbook Tw = myExcel.Application.Workbooks.Open(Excel_File_Name,oMissing,true,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing,oMissing);独占的方式打开这个文件。直接导出
    this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls");
    this.Page.Response.Charset = "GB2312"; 
    this.Page.Response.ContentEncoding =System.Text.Encoding.Default;
    this.Page.Response.ContentType = "application/vnd.ms-excel";
    System.IO.StringWriter textstring = new System.IO.StringWriter(); 
    HtmlTextWriter htmltext = new HtmlTextWriter(textstring);
    this.DataGrid1.RenderControl(htmltext);
    this.Page.Response.Write(textstring); 
    this.Page.Response.End();
      

  5.   

    http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=6AFBF00B-459D-4642-AD14-8A4765FFAFCC
      

  6.   

    用ActiveX技术来操作Excel的一个最大的问题是有时就是关不了后台的Excel,我试了很多方法,有时能关有时不能关,很奇怪。你可以用ODBC来将数据写入Excel文件,而不用后台打开Excel,这样效率要高得多,而且不存在关不了进程的问题!
      

  7.   

    在C#中使用Excel,要先做一点准备工作,通过查找(前提是你安装Visual Studio.Net和Excel 2000),在你的计算机中找到TlbImp和Excel9.olb,将他们复制到一个文件夹中,在DOS窗口中执行 TlbImp Excel9.olb,这时会产生以下三个文件:Excel.dll、Office.dll和VBIDE.dll
    然后引用
    //创建一个Excel文件
    Excel.Application myExcel = new Excel.Application ( ) ;
    myExcel.Application.Workbooks.Add ( true ) ;
    //让Excel文件可见
    myExcel.Visible=true;
    //第一行为报表名称
    myExcel.Cells[1,4]="普通报表";
    //逐行写入数据,
    for(int i=0;i<11;i++)
    {
    for(int j=0;j<7;j++)
    {
    //以单引号开头,表示该单元格为纯文本
    myExcel.Cells[2+i,1+j]="'"+myData[i,j];
    }
    } }
    myData是个数组 把你的数据放里面就行了
      

  8.   

    在Excel中单击“插入”——“名称”——“定义”,将你要插入数据的单元格定义为一个名称(包括标题行,标题行会自动作为字段名),然后你就可能用ODBC来访问它了。