2013-04-22 97 views
0

我想打開,並通過使用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

回答

1

你有沒有嘗試過這樣的:

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