天道酬勤,学无止境

mergefield

Replace MergeFields in a Word 2003 document and keep style

Question I've been trying to create a library to replace the MergeFields on a Word 2003 document, everything works fine, except that I lose the style applied to the field when I replace it, is there a way to keep it? This is the code I'm using to replace the fields: private void FillFields2003(string template, Dictionary<string, string> values) { object missing = Missing.Value; var application = new ApplicationClass(); var document = new Microsoft.Office.Interop.Word.Document(); try { // Open the file foreach (Field mergeField in document.Fields) { if (mergeField.Type == WdFieldType

2021-07-11 09:45:35    分类:技术分享    c#   interop   ms-word   vsto   mergefield

Position cursor at start/end of Word document

Question We are manipulating our Word 2007 documents from .Net using Word Interop. Mostly doing stuff with fields as in: For Each f In d.Fields f.Select() //do stuff with fields here Next This leaves the last field in the document selected. So, for the sake of neatness we would like to position the cursor at the end of the document (or even the start would be OK). Googling for the answer doesn't throw up much ... the nearest I can get seems to be suggesting we need to involve ourselves with ranges or bookmarks. There's a GoTo method for the Document object but none of the WdGoToItem options it

2021-04-26 15:54:11    分类:技术分享    .net   interop   ms-word   mergefield