Microsoft.Office.Interop.Word.ApplicationClass msDoc = new Microsoft.Office.Interop.Word.ApplicationClass();
msDoc.Visible = false;
msDoc.Application.Visible = false;
msDoc.Documents.Open(ref docPath, ref UNKNOWN,
ref READ_ONLY, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN, re开发者_高级运维f UNKNOWN, ref UNKNOWN);
msDoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
msDoc.ActiveDocument.SaveAs(ref target, ref format,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN, ref UNKNOWN,
ref UNKNOWN, ref UNKNOWN);
The problem is that when SaveAs is executed a dialog appears. I'm trying to disable that dialog programmatically so that the user never has to provide input or configuration of Office/Word. The utility I'm writing could potentially have 100s of saves so a pop-up dialog isn't good.
I was able to figure out a programmatic solution by setting the following option in my code:
msDoc.Application.Options.WarnBeforeSavingPrintingSendingMarkup = false;
Configuration wise I found you could also disable this Office feature by going into:
Word Options->Trust Center->Privacy Options->Uncheck "Warn before printing, saving or sending a file that contains tracked changes or comments"
msDoc.Options.WarnBeforeSavingPrintingSendingMarkup = false;
or
Word Options->Trust Center->Privacy Options->Uncheck "Warn before printing, saving or sending a file that contains tracked changes or comments"
does not work for me.
What works for me is:
msDoc.ActiveWindow.Close(WdSaveOptions.wdDoNotSaveChanges);
精彩评论