Get Field Book Sign

I use the Microsoft.Office.Interop.Word namespace in a console application to retrieve form data from an MSWord document. This MSWord document has fields, each of which is assigned a bookmark, which I use as an identifier.

I would like to get the value of the field from its tab and save it in the dictionary. I can get only the value of each field, but not the tab AND field.

Is there a way that I could do something like wdField.Result.Bookmark to get a field bookmark? I looked at the MSDN documentation, but it's hard for me to get it right. Here is the foreach loop that I am listing with:

foreach (Field wdField in oWordDoc.Fields) { wdField.Select(); string fieldText = wdField.Result.Text Console.WriteLine(fieldText); //string fieldBookMark = wdField.Result.BookMark } 
+4
source share
1 answer

KazJaw is right: if you have all the targeted text for bookmarks, you can only rely on BookMarks . Code example:

 foreach (Bookmark bookMark in oWordDoc.Bookmarks) { string bmName = bookMark.Name; Range bmRange = bookMark.Range; string bmText = bmRange.Text; } 

Or:

 Range bmRange = oWordDoc.Bookmarks["bookmark name"].Range; 
+3
source

Source: https://habr.com/ru/post/1494670/


All Articles