Free Support Forum - aspose.com

Inserting formatted HTML into a Word Footnote

I have a Word document in Aspose.Words. I have added a number of Footnotes. For each Footnote I would like to remove the existing text and replace with formatted data. This formatted data is a html snippet which contains 1 or more paragraphs some of which include anchor tags. Is there any way in which this could be achieved?

Hi Nigel,


Thanks for your inquiry. Sure, you can replace existing text of a Footnote with HTML string by using the following code snippet:

Document
doc = new Document(@“C:\Temp\in.docx”);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Footnote note in doc.GetChildNodes(NodeType.Footnote, true))

{

if (note.FootnoteType.Equals(FootnoteType.Footnote))

{

foreach (Paragraph para in note.Paragraphs)

{

if (para.Equals(note.FirstParagraph))

note.FirstParagraph.Runs.Clear();

else

para.Remove();

}

builder.MoveTo(note.FirstParagraph);

builder.InsertHtml("

para 1

para 2 with anchor

");

}

}

doc.Save(@"C:\temp\out.docx");


I hope, this helps.

Best regards,