Is it possible to insert a HTML fragment into a TableCell for a WordProcessingDocument created using OpenXML?
For example, when I use:
public void WriteWordFile()
{
var fileName = HttpContext.Current.Request.PhysicalApplicationPath + "/temp/" + HttpContext.Current.Session.SessionID + ".docx";
using (var wordDocument = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document, true))
{
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
var body = mainPart.Document.AppendChild(new Body());
var table = new Table();
var tr = new TableRow();
var tc = new TableCell();
tc.Append(new Paragraph(new Run(new Text("1"))));
tr.Append(tc);
table.Append(tr);
body.Append(table);
}
the Word document prints a simple "1" with no formatting as expected.
However, what I want to do is write:
public void WriteWordFile()
{
var fileName = HttpContext.Current.Request.PhysicalApplicationPath + "/temp/" + HttpContext.Current.Session.SessionID + ".docx";
using (var wordDocument = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document, true))
{
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
var body = mainPart.Document.AppendChild(new Body());
var table = new Table();
var tr = new TableRow();
var tc = new TableCell();
tc.Append(new Paragraph(new Run(new Text("<span style=\"bold\">1</span>"))));
tr.Append(tc);
table.Append(tr);
body.Append(table);
}
}
The Word document prints the HTML markup "<span style="bold">1</span>
" instead of a bold "1".