![](/img/trans.png)
[英]How can i make that my application will close and start and close automatic over and over again?
[英]How I can close a excel windows automatic?
我想使用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);
}
}
我如何使其自动?
您是否尝试过:
app.DisplayAlerts = false;
也许还可以通过以下两种方式进行其他隐藏(如果需要):
app.Visible = false;
app.ScreenUpdating = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.