簡體   English   中英

Visual C#-如何將文本寫入Word文檔模板?

[英]Visual C# - How do I write text to a Word Document Template?

正在開發一個程序,該程序涉及記錄各個人的姓名和地址並將其打印在3x10的標簽紙上。 有問題的是這里的WL-875模板。 我為嘗試使其工作而編寫的代碼如下(我有點在黑暗中射擊,因為我以前從未做過,所以它是不完整的)。 在哪里可以建立一個循環,在該循環中,只要在標簽隊列中有標簽,就可以在模板中標記要添加的位置,添加必要的信息,然后向下移動到下一個位置,從而建立一個循環?

如果我弄錯了細節或什么都沒做,就像我說的那樣,那么我完全不知道該怎么做,即使我做對了。

using Word = Microsoft.Office.Interop.Word;
using System.Reflection;

public Print(LabelQueue queue, User a)
    {
        InitializeComponent();

        object oMissing = System.Reflection.Missing.Value;
        object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

        //Start Word and create a new document.
        Word._Application oWord;
        Word._Document oDoc;
        oWord = new Word.Application();
        oWord.Visible = false;
        oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
            ref oMissing, ref oMissing);

        // Declare a template and add to word document
        object oTemplate = "c:\\GitHub\iD2015\PO\Resources\MyTemplate.dotx";
        oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing,
            ref oMissing, ref oMissing);

     }

MailMerge專為此類事情而設計。 這是一個至少應該幫助您入門的鏈接: https : //support.microsoft.com/zh-cn/kb/301659

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM