尝试退出没有对话框的C#Excel工作簿 [英] Trying to exit C# Excel Workbook without a dialog box
问题描述
我正在使用Microsoft Office Interop编辑一些excel文件,当我关闭它们时,我使用
I am using Microsoft Office Interop to edit some excel files and when I close them I use
outputExcelWorkBook.Close(false, paramMissing, paramMissing);
但是,即使我将false
作为第一个参数传递,仍会出现一个对话框.我也尝试过使用true
并给它一个文件路径作为第二个参数,但是在两种情况下都会出现一个对话框,询问我是否要在关闭之前保存.谁能告诉我这是怎么回事?
But a dialog box still comes up, even though I passed false
as the first parameter. I have also tried it with true
and giving it a file path as the second parameter but in both cases a dialog box comes up asking me if I want to save before closing. Can anyone tell me what's going on here?
推荐答案
尝试将Application.DisplayAlerts
属性设置为false
.对于大多数自动化例程,将属性设置为false
可能会很有用.在返回之前,请记住要恢复以前的值.
Try setting the Application.DisplayAlerts
property to false
. You may find it useful to set this property to false
for the majority of your automation routines. Remember to restore the previous value before returning.
Application applicationInstance = ...;
var oldDisplayAlertsValue = applicationInstance.DisplayAlerts;
applicationInstance.DisplayAlerts = false;
try
{
outputExcelWorkBook.Close(false, Missing.Value, Missing.Value);
}
finally
{
appliationInstance.DisplayAlerts = oldDisplayAlertsValue;
}
这篇关于尝试退出没有对话框的C#Excel工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!