I have a Word Template with a lot of content controls that are populated by SharePoint and InfoPath form. I want to loop through all the content controls and update the text and format (Italic/Font Size, etc) based on matches to the Tag. I’ve tried it with OpenXml but haven’t been able to change the format of the text within the content control and I want to see how it’s done with Aspose.Words.
Thanks in advance.
Thanks for your inquiry. I think, you can achieve this by using the following code snippet:
Document doc = new Document(MyDir + @"input.docx");
foreach(StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
NodeCollection runNodes = sdt.GetChildNodes(NodeType.Run, true);
foreach(Run run in runNodes)
run.Font.Italic = true;
run.Font.Size = 12;
doc.Save(MyDir + @"output.docx");
I hope, this helps.