如何在C#中编程实现,向WORD模板中固定的位置填入数据?(例如就象介绍信的套打)

解决方案 »

  1.   

    使用标签。例如:在word模版中插入一个名为lblStartYear标签,然后使用如下代码:
        Microsoft.Office.Interop.Word.ApplicationClass ac = new Microsoft.Office.Interop.Word.ApplicationClass();

        object   template = Application.StartupPath + "\\xwbl.dot";
        object   newTemplate = Missing.Value;     
        object   documentType = Missing.Value;     
        object   visible = true;     
        
        Microsoft.Office.Interop.Word.Document wordDoc = ac.Documents.Add(ref   template,   ref   newTemplate,   ref   documentType,   ref   visible);
        wordDoc.Activate();    object lblStartYear = "lblStartYear";
        if (ac.ActiveDocument.Books.Exists("lblStartYear"))
        {
    ac.ActiveDocument.Books.get_Item(ref lblStartYear).Select();
    ac.Selection.TypeText("2046");
        }