将Word转换为PDF-禁用“保存"对话 [英] Convert Word to PDF - Disable "save" Dialog

查看:147
本文介绍了将Word转换为PDF-禁用“保存"对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用c#编写的Word to PDF Converter,除了一件事外,它可以正常工作.有时(在某些Word文件上)在后台有一条消息,其中有在源文件中保存更改->是,无取消-但我没有在源文件中进行任何更改.我只是想从Word文件创建PDF文件,而无需进行任何更改.

I have a Word to PDF Converter written in c# which works fine except of one thing. Sometimes (on some Word Files) there is a Message in Background with Save Changes in Source File -> YES NO CANCEL - but I dont do any changes in Source file. I just wanna create a PDF File from the Word File, without changing anything.

是否有可能禁用此提示,或自动设置为否". ?

So is there a Possibility to disable this Prompt, or set automatically to "NO". ?

这是我的代码:

// Create an instance of Word.exe
        Microsoft.Office.Interop.Word._Application oWord = new  Microsoft.Office.Interop.Word.Application();

        // Make this instance of word invisible
        oWord.Visible = false;

        oWord.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

        oWord.Options.SavePropertiesPrompt = false;
        oWord.Options.SaveNormalPrompt = false;

        // Interop requires objects.
        object oMissing = System.Reflection.Missing.Value;
        object isVisible = true;
        object readOnly = true;
        object oInput = input;
        object oOutput = output;
        object oFormat = format;

        // Load a document into our instance of word.exe
        Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        // Make this document the active document.
        oDoc.Activate();

        // Save this document in Word 2003 format.
        oDoc.SaveAs(ref oOutput, ref oFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        // Always close Word.exe.
        oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

推荐答案

您是否尝试将false作为第一个参数传递给Quit?

Did you try passing false as the first argument to Quit?

这篇关于将Word转换为PDF-禁用“保存"对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆