我想使用 C# 打开和更改 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);
                             }
                         }

我怎样才能让它自动化?