我想从 Word 模板自动打印发票。我想我的逻辑是错误的,但我只是不知道正确的编码方式。这是我当前的代码
Selection wrdSelection;
MailMerge wrdMailMerge;
MailMergeFields wrdMergeFields;
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document wrdDoc = new Document();
wordApp.Visible = false;
wrdSelection = wordApp.Selection;
object oMissing = System.Reflection.Missing.Value;
// PUT MY EXISTING TEMPLATE FILE INTO WORD DOCUMENT
wrdDoc = wordApp.Documents.Add(Properties.Resources.invoiceTemp,oMissing,oMissing, oMissing);
// RETREIVE MAIL MERGE PROPERTIES FROM THE DOCUMENT IN HOPES OF UTILIZING IT
wrdMailMerge = wrdDoc.MailMerge;
wrdDoc.Select();
wrdMergeFields = wrdMailMerge.Fields;
如果有帮助,这里是我的模板上的合并字段:
date_issued
, month_covered
, invoiceNo
, tuition
, lunchFee
, discount
, studentNo
, studentName
, amountDue
, amountPaid
, balance
, penalty
,status
现在,如何将使用我的应用程序检索的数据添加到从模板中获取所有属性的文档中?