如何不使用microsoft.office.interop.word保存文档

问题描述:

只是想知道是否有人使用Microsoft.Office.Interop.Word在创建后不保存文档.

Just wondering if anyone knows how to not save a document after creation when using Microsoft.Office.Interop.Word.

基本上,我正在使用邮件合并从c#打印一份报告,完成了文档的编写,将值传递给它没有问题,然后我可以打印它而没有任何问题,但是,我只需要打印文档,我就可以了不需要在计算机上保存副本.

Basically i am using mail merge to print off a report from c#, the document get made, values are passed to it no problem and i can then print it without any issues, however, I only need to print the document, I do not need to save a copy on the computer.

将所有值传递给文档后,我将使用以下代码打印并关闭文档:

Once i have passed all the values to the document, i use the following code to print and close the document:

wordDoc.PrintOut();
wordDoc.Close();
wordApp.Application.Quit();

但是,这会打印文档,然后弹出保存"对话框,询问将文档保存在何处.我不希望这样,因为单击取消"会产生错误(并且需要用户进行其他不需要的交互),并且我不需要保存文件.

However, this prints the document and then the 'Save' dialog pops up, asking where to save the document. I dont want this as clicking cancel produces an error (and requires another unwanted interaction from the user), and i dont need to save the file.

有什么想法吗?

使用Visual Studio 2012,.NET 4.0,并且我尝试将以下文件类型用于Office文档:.doc,.dot,.docx,.dotx.

Using Visual Studio 2012, .NET 4.0, and i have tried using the following files types for the office document: .doc, .dot, .docx, .dotx.

您可以将SaveChanges参数作为wdDoNotSaveChanges传递给Close方法,以跳过保存部分.

You can pass SaveChanges parameter as wdDoNotSaveChanges to the Close method to skip the saving part.

看看:

如何关闭Word文档的运行实例? (C#)

查看全文