如何关闭excel窗口自动?

问题描述:

我想打开,并通过使用C#如何关闭excel窗口自动?

更改Excel单元格,它的工作原理,但如果我保存文件,我得到从Excel -.-一个窗口,每次我必须点击按钮。看到图片。

这里是我的代码:

foreach (string file in Directory.GetFiles(path)) 
         { 
          MSExcel.Workbook book1 = null; 
          MSExcel.Worksheet sheet1; 
          MSExcel.Range range_A1; 

          try 
          { 
           book1 = app.Workbooks.Open(file); 
           sheet1 = (MSExcel.Worksheet)book1.Worksheets[1]; 
           range_A1 = sheet1.GetRange(cell); 

           string content = range_A1.Value2.ToString(); 

           if (content == value || content == value2) 
           { 

            range_A1.Value2 = string.Empty; 
            book1.Save(); // here i save the value 
            Console.WriteLine(count +" - OPEN AND CHANGE - " + file + " SAVE"); 
           } 
           else 
           { 

            Console.WriteLine(count + " - OPEN - " + file + " NOT SAVE"); 
           } 

           count++; 
          } 
          catch (Exception) 
          { 
           count++; 
           Console.WriteLine(count + " - ERROR FILE " + file); 
           liste.Add(file); 
          } 
          finally 
          { 
           book1.Close(false); 

          } 

         } 

enter image description here

我怎样才能使它自动?

+0

看看[这里](http://superuser.com/questions/83199/can not-out-of-compatibility-mode-in-excel-2007),我认为这可以帮助你。 – 2013-04-22 13:46:22

你有没有尝试过这样的:

app.DisplayAlerts = false; 

也许还这两个额外的隐藏(如果需要):

app.Visible = false; 
app.ScreenUpdating = false; 
+0

对象应用程序没有这种方法 – Tarasov 2013-04-22 13:17:08

+0

不是应用程序类型['Microsoft.Office.Interop.Excel.Application'](http://msdn.microsoft.com/zh-cn/library/microsoft.office .interop.excel._application.displayalerts.aspx)? – Oliver 2013-04-22 13:59:58

+0

不,我使用Tcks.MSOFFICE.Excel http://msofficefornet.codeplex.com/wikipage?title=Working%20with%20MS%20Office%20Wrapper%20for%20.NET – Tarasov 2013-04-23 06:10:04