I am reading a Word document using .Net Xceed DocX library like this:
var result = new MemoryStream();
using (DocX document = DocX.Load(stream))
{
var paragraphs = document.Paragraphs;
foreach (var paragraph in paragraphs)
{
if (paragraph.Text.Contains("{{Instructions}}"))
{
var bulletedList = document.AddList(null, 0, ListItemType.Bulleted);
document.AddListItem(bulletedList, "Bullet Point 1");
document.AddListItem(bulletedList, "Bullet Point 2");
document.AddListItem(bulletedList, "Bullet Point 3");
paragraph.InsertListAfterSelf(bulletedList);
paragraph.RemoveText(0);
break;
}
}
document.SaveAs(result);
}
I search for a term called {{Instructions}} and I want to replace it with a bulleted list. This works but the list has the default font family and font size.
I want to find either the current paragraph’s font or the document’s font and then pass a Formatting object with these font values to the AddListItem method.
I cannot find the current font family or font size as a property on the paragraph or the document.
I can see these values in the Xml property of the paragraph, so I could extract them from there but that’s not ideal.