I am getting some data and from it I am generating a custom XML file. I have a Microsoft Office Word document with Rich Text Content Controls in it. I bind the data to the Content Controls with this method:
private void BindControl(WordprocessingDocument doc, string controlTitle, DocumentFormat.OpenXml.StringValue xPathValue)
{
DataBinding dataBinding = new DataBinding()
{
XPath = xPathValue,
StoreItemId = "{SomeID}"
};
SdtElement sdtElement = doc.MainDocumentPart.Document.Descendants<SdtElement>()
.Where(
element =>
element.SdtProperties.GetFirstChild<SdtAlias>() != null &&
element.SdtProperties.GetFirstChild<SdtAlias>().Val == controlTitle).FirstOrDefault();
if (sdtElement != null)
{
sdtElement.SdtProperties.Append(dataBinding);
}
}
However this method only inserts the text with no formating.
I want to make some of the thext in the output document Bold, other with different color and then I must make hyperlinks.
I tried to insert the html formating in the XML file but as result it is not rendered, just displayed.