79352227

Date: 2025-01-13 12:51:20
Score: 2
Natty:
Report link

I have found a solution to my problem.

Thanks to @itallmakescents, I was able to use the OpenXML Productivity Tool to compare the XML output of what my program generated vs. my expectations.

It turns out the first <w:rPr> tag is not a RunProperties tag, but a ParagraphMarkRunProperties tag instead. I needed to remove the FontSize instance belonging to the RunProperties tag, and change the FontSize of the ParagraphMarkRunProperties to 1pt.

My final solution can be seen here:

OpenXML.Table lastTable = oNewReportDoc.MainDocumentPart.Document.Body
    .Descendants<OpenXML.Table>()
    .Last();

OpenXML.Paragraph paraToEdit = lastTable.NextSibling<OpenXML.Paragraph>();


List<RunProperties> runProps = paraToEdit.Descendants<RunProperties>().ToList();

List<ParagraphMarkRunProperties> pMarkProps = paraToEdit.Descendants<ParagraphMarkRunProperties>().ToList();

foreach (RunProperties rp in runProps)
{
    rp.RemoveAllChildren<FontSize>();
    rp.Remove();
}

foreach (ParagraphMarkRunProperties prp in pMarkProps)
{
    prp.RemoveAllChildren<FontSize>();
    prp.AddChild(new FontSize() { Val = "2" });
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @itallmakescents
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: jbrrr