Current location - Quotes Website - Personality signature - C# development, how to get all the bookmarks in the Word document, can now be operated by the signature of the known book.
C# development, how to get all the bookmarks in the Word document, can now be operated by the signature of the known book.
Refer to the code implemented with class library Spire. Documentation:

C#

(main code segment)

Documents? Doctor. =? New? Document ();

Doctor. LoadFromFile(" bookmark . docx ");

BookmarksNavigator? Navigator? =? New? bookmarks navigator(doc);

A navigator. MoveToBookmark(" bookmark _ 1 ");

TextBodyPart? textBodyPart? =? A navigator. GetBookmarkContent();

String? Words? =? null

foreach? (var? Articles? Are you online? textBodyPart。 Text item)

{

What if? (item? Is it? Paragraph)

{

foreach? (var? childObject? Are you online? (item? As? Paragraph). Child object)

{

What if? (childObject? Is it? Text range)

{

Words? +=? (childObject? As? TextRange)。 Text;

}

}

}

}

Console. WriteLine (text); You can also refer to the original text: C# to get Word bookmarks.