Hi
Thanks for your inquiry. Maybe the following code could be useful for you:
public void Test188()
{
// Open document
Document doc = new Document(@"Test188\SectionTest_Aspose.dot");
// Create document buider
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Bookmark bk in doc.Range.Bookmarks)
{
// Move docuemnt builder cursor to the bookmark
builder.MoveToBookmark(bk.Name);
// set new style identifier
builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = GetHeading(builder.CurrentParagraph);
}
// Save output docuemnt
doc.Save(@"Test188\out.doc");
}
/// <summary>
/// Method returns any heading style of any paragraph above the node
/// if there are no headign paragraphs above the node Normal style is returned
/// </summary>
private StyleIdentifier GetHeading(Node node)
{
StyleIdentifier style = StyleIdentifier.Normal;
Node currentNode = node;
while(currentNode!=null)
{
// check whether current node is paragraph.
// If so we should che its style
// and return headign style if current paragraph is heading paragraph
if(currentNode.NodeType.Equals(NodeType.Paragraph))
{
Paragraph curretnPar = (Paragraph) currentNode;
if(IsHeading(curretnPar.ParagraphFormat.StyleIdentifier))
{
style = curretnPar.ParagraphFormat.StyleIdentifier;
break;
}
}
// move to the previouse node
currentNode = currentNode.PreviousPreOrder(node.Document);
}
return style;
}
/// <summary>
/// Returns true if identifier is an identifier of heading paragraph
/// </summary>
private bool IsHeading(StyleIdentifier style)
{
switch (style)
{
case StyleIdentifier.Heading1:
case StyleIdentifier.Heading2:
case StyleIdentifier.Heading3:
case StyleIdentifier.Heading4:
case StyleIdentifier.Heading5:
case StyleIdentifier.Heading6:
case StyleIdentifier.Heading7:
case StyleIdentifier.Heading8:
case StyleIdentifier.Heading9:
return true;
default:
return false;
}
}
Hope this helps.
Best regards.
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team