disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

☆樱花仙子☆ 提交于 2019-11-27 21:46:43

问题


I am using Ms Office Interop assemblies to create a MS Project file. To save the file created, I am using FileSaveAs method and it prompts a message saying that if you want to replace the existing file. I want to suppress the message, and I didn't find any parameter in FileSaveAs method for this purpose. Any Idea on this? I'am using C# as my programming language.


回答1:


I ran into this issue when working with Excel Interop. The best I've been able to find is to disable all Office alerts, like this:

Microsoft.Office.Interop.MSProject.Application msProjectApp = new Microsoft.Office.Interop.MSProject.Application();
msProjectApp.DisplayAlerts = false;



回答2:


Never double dot COM objects, as they will not be released and this will leave excel open on your server. Unfortunately I have crashed servers because of this.

private void InitialiseExcel()
{
    if (excelApp == null)
        excelApp = new Excel.Application();
    // Turn off User Prompts
    excelApp.DisplayAlerts = false;
    // Turn off screen updating so we do not get flicker
    var app = excelApp.Application;
    app.ScreenUpdating = false;
    // Specifies the state of the window;
    excelApp.WindowState = Excel.XlWindowState.xlMinimized;
    Marshal.ReleaseComObject(app);
}


来源:https://stackoverflow.com/questions/3360481/disabling-overwrite-existing-file-prompt-in-microsoft-office-interop-filesaveas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!