excel.quit();??不过进程那边好像还是要等程序退出才会消失哦,
不清楚,等待高手帮忙
up

解决方案 »

  1.   

    try{
    workbook.SaveAs(this.strExcelFilePath,Excel.XlFileFormat.xlWorkbookNormal,oMissing,oMissing,oMissing,oMissing,
    Excel.XlSaveAsAccessMode.xlShared,oMissing,oMissing,oMissing,oMissing,oMissing);
    }
    catch( Exception e )
    {

    }
    finally
    {
    if(range != null)
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
    }
    if(worksheet != null)
    {
    System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
    }
    if(workbook != null)
    {
    workbook.Close(isSave,oMissing,oMissing);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
    }
    if(excel != null)
    {
    excel.Quit();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
    }
    workbook = null;
    worksheet = null;
    range = null;
    excel = null;
    GC.Collect();

    }
      

  2.   

    还有需要在DCOM中配置一下Excel的访问权限
      

  3.   

    将对excel的操作写到一个函数里,在调用函数后再执行System.GC.Collect();
    这样应该就可以了。
    如:
    private void Button1_Click(object sender, System.EventArgs e)
    {
              string strFileName = ExpExcel();
              System.GC.Collect();
              Response.Redirect(strFileName);
    } private string ExpExcel()
    {
    string filename=Server.MapPath(".")+"\\bin\\af.xls";
    FileInfo sTemplate=new FileInfo(Server.MapPath(".")+"\\bin\\normal.xls");
    sTemplate.CopyTo(filename,true);
    object missing=Missing.Value;
    Excel.Application excel = null;
    Excel.Workbooks workbooks = null;
    Excel.Workbook workbook = null;
    Excel.Sheets sheets = null;
    Excel.Worksheet worksheet = null;
    Excel.Range oCells=null;
     
    excel = new Excel.ApplicationClass();
    excel.Visible = false;
    excel.DisplayAlerts = false;workbooks = excel.Workbooks;
    workbook = workbooks.Open(filename,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing);
    sheets = workbook.Worksheets;
    worksheet = (Excel.Worksheet)sheets[1];
    worksheet.Name  = "First Sheet";
    oCells = worksheet.Cells; worksheet.Cells[5,5]="'"+"99999999";
    workbook.Save ();  
    //worksheet.SaveAs(filename);  
     // workbook.Close();//Quit Excel and thoroughly deallocate everything
    excel.Quit();
    System.Runtime.InteropServices.Marshal .ReleaseComObject(oCells) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(worksheet);
    System.Runtime.InteropServices.Marshal .ReleaseComObject(sheets) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(workbook);
    System.Runtime.InteropServices.Marshal .ReleaseComObject(workbooks) ;
    System.Runtime.InteropServices.Marshal .ReleaseComObject(excel);
    excel = null ; workbooks = null ; workbook = null;
    sheets = null ; worksheet = null ; oCells = null;return filename;
    }
      

  4.   

    得用垃圾回收机制回收,我用winForm时,也出现这个问题后来在csdn上找了一贴,就解决了,你搜搜
      

  5.   

    gesnpt(gesnpt) 的可以,用两个函数