Hi,
I want to remove the highlighting from a specific text range in Word but it does not apply to the footnote number. How can I achieve it ?
I used the document visitor (see code below)
private Document DisableXbrlMappingHighlighting(Document document)
{
ChangeHighlightColor changeHighlightColor = new ChangeHighlightColor(Color.Empty);
foreach (Bookmark bookmark in document.Range.Bookmarks)
{
Node currentNode = bookmark.BookmarkStart;
while (currentNode != bookmark.BookmarkEnd && currentNode != null)
{
currentNode = currentNode.NextPreOrder(document);
currentNode.Accept(changeHighlightColor);
currentNode = currentNode.NextSibling;
}
currentNode = bookmark.BookmarkStart;
while (currentNode != bookmark.BookmarkEnd && currentNode != null)
{
currentNode = currentNode.NextPreOrder(document);
if (currentNode.NodeType == NodeType.Paragraph || currentNode.NodeType == NodeType.Shape)
{
currentNode.Accept(changeHighlightColor);
}
}
currentNode = bookmark.BookmarkStart;
while (currentNode != bookmark.BookmarkEnd && currentNode != null)
{
currentNode = currentNode.NextPreOrder(document);
if (currentNode.NodeType == NodeType.Run || currentNode.NodeType == NodeType.Shape)
{
currentNode.Accept(changeHighlightColor);
}
}
}
return document;
}
public class ChangeHighlightColor : DocumentVisitor
{
public ChangeHighlightColor(System.Drawing.Color highlighColor)
{
mHighlighColor = highlighColor;
}
public override VisitorAction VisitShapeStart(Shape shape)
{
ChangeFont(shape.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitShapeEnd(Shape shape)
{
ChangeFont(shape.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitFieldEnd(Aspose.Words.Fields.FieldEnd fieldEnd)
{
ChangeFont(fieldEnd.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitFieldSeparator(Aspose.Words.Fields.FieldSeparator fieldSeparator)
{
ChangeFont(fieldSeparator.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitFieldStart(Aspose.Words.Fields.FieldStart fieldStart)
{
ChangeFont(fieldStart.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitFormField(Aspose.Words.Fields.FormField formField)
{
ChangeFont(formField.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitParagraphEnd(Paragraph paragraph)
{
ChangeFont(paragraph.ParagraphBreakFont);
return VisitorAction.Continue;
}
public override VisitorAction VisitRun(Run run)
{
ChangeFont(run.Font);
return VisitorAction.Continue;
}
public override VisitorAction VisitSpecialChar(SpecialChar specialChar)
{
ChangeFont(specialChar.Font);
return VisitorAction.Continue;
}
private void ChangeFont(Font font)
{
font.HighlightColor = mHighlighColor;
}
private readonly System.Drawing.Color mHighlighColor = System.Drawing.Color.Transparent;
}
Here the source file (res.docx) and result (testout.xhtml). testres.zip (68.0 KB)
Regards,
Guido