这些代码在C#中怎么无法关闭EXCEL进程请大家帮忙看看 Excel.Application app = new Excel.ApplicationClass();
Excel.Workbook workBook;
Excel.Worksheet workSheet;
DataSet ds=new DataSet();
string str="";
string name="";
try
{
//打开模板文件,得到WorkBook对象
workBook = app.Workbooks.Open(Main.FilePath,missing,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing,missing,missing,missing); //得到WorkSheet对象,并且获得Excel中第一个Sheet的名称
workSheet = (Worksheet)workBook.Sheets.get_Item(1);
Main.SheetName=workSheet.Name;
/////////////////////////////////////////////////////////////////////
//得到Excel文件中最后一列的值
str="select top 2 * from ["+Main.SheetName+"$]";
ds=Bd.ExcelSelect(Main.FilePath,str);
foreach(DataColumn col in ds.Tables["table"].Columns)
{
name=col.ColumnName;
}
//根据相应位置写入以个字段名称
for(int i=1;i<=65535;i++)
{
for(int a=1;a<=255;a++)
{
r=workSheet.get_Range(workSheet.Cells[i,a],workSheet.Cells[i,a]);
if(r.Value2!=null)
{
if(r.Value2.ToString()!="")
{ if(r.Value2.ToString()==name)
{

row=i;
col=a;
if(r.Value2.ToString()!="Tag")
{
row=i;
col=a+1;
workSheet.Cells[row,col]="Tag";
workBook.Save();
}
goto x;
}
}
}
}
}
x:

workBook.Close(missing,missing,missing);
app.Workbooks.Close();
app.Application.Quit();
app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
System.Runtime.InteropServices.Marshal.ReleaseComObject(r); workSheet=null;
workBook=null;
app=null;
r=null;
GC.Collect();

 return ds;
}

catch(Exception ex)
{
throw ex;

workBook.Close(null,null,null);
app.Workbooks.Close();

app.Application.Quit();
app.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
System.Runtime.InteropServices.Marshal.ReleaseComObject(r);

workSheet=null;
workBook=null;
// r=null;
app=null; GC.Collect();

return ds;
}
}