Interop.Word
我从 .doc 文件创建了一个邮件合并。
它工作正常,从指定的数据源加载数据,我可以使用该方法查看填充的数据wDoc.MailMerge.EditMainDocument();
但我不想只打开它,而是想打印出 MainDocument,这意味着如果我的邮件合并数据源中有 15 个条目,我想打印 15 页。
当我执行 wDoc.PrintOut 时,我的基本文档文件被打印出来,没有填写数据!
这可能吗,怎么做?
到目前为止,这是我的代码:
Application wApp = new Application();
Document wDoc = wApp.Documents.Open(ref oFile, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
wDoc.Activate();
wApp.ActivePrinter = "TestPrinter";
wDoc.MailMerge.OpenDataSource(wDoc.MailMerge.DataSource.Name, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
wDoc.MailMerge.Execute(ref missing);
wDoc.MailMerge.EditMainDocument();
wDoc.MailMerge.Execute(ref missing);
wDoc.PrintOut(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
wDoc.Close(ref saveOptionsObject, ref missing, ref missing);
wApp.Quit(ref saveOptionsObject, ref missing, ref missing);