Free Support Forum - aspose.com

Aspose word bookmark apply style

Hi,

Please help on how to apply style on already created bookmark?

the word template already has bookmarks…through aspose find the bookmark and apply text and style to it.

Please advise.

Hi there,


Thanks for your inquiry. Please use ParagraphFormat.Style property to get or set the paragraph style applied to paragraph. Following code example shows how to set style of paragraphs of a bookmark.

If you face any issue, please share your input and expected output documents here for our reference. We will then provide you more information about your query.

Document doc = new Document(MyDir + “in.docx”);<o:p></o:p>

Bookmark bm = doc.Range.Bookmarks["bm"];

Node node = bm.BookmarkStart;

node = node.ParentNode;

while (bm.BookmarkEnd != node)

{

if (node.NodeType == NodeType.Paragraph)

{

Paragraph para = (Paragraph)node;

para.ParagraphFormat.ClearFormatting();

foreach (Run run in para.Runs)

{

run.Font.ClearFormatting();

}

//set the paragraph style

para.ParagraphFormat.StyleName = "Heading 1";

}

node = node.NextPreOrder(doc);

}

doc.Save(MyDir + "17.4.docx");