Data merge word3/11/2023 OWordDoc = (ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing) įoreach (Word.Field myMergeField in oWordDoc.Fields) Word.Document oWordDoc = new Word.Document() Word.Application oWord = new Word.Application() The code to replace a mergefield with a string is like this: public static void TextToWord(string pWordDoc, string pMergeField, string pValue) Here is a simple step by step tutorial on how to do this. In addition, if some of your fields contain line breaks, use this: nr = my_address_text_contains_line_breaks.Replace(Environment.NewLine, "MS_Doc_New_Line") So, your template(c:\my_template.docx) should be like: Ĭongratulations on yourr property. docx file, and you need to specify your fields in it: Your template(c:\my_template.docx) will be just like normal. Mailmerge(sourceFile, filePath, nr, dt.Columns) String filePath = "c:\final.docx" //this is where your result file locate String sourceFile = "c:\my_template.docx" //this is where you store your template MainDocumentPart mainPart = myDoc.MainDocumentPart Īnd use them like this: DataTable dt = new DataTable() Using (WordprocessingDocument myDoc = true)) If (filepaths != null
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |