是否可以将 HTML 片段插入到使用 OpenXML 创建的 WordProcessingDocument 的 TableCell 中?
例如,当我使用:
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);
}
Word 文档打印一个简单的“1”,没有预期的格式。
然而,我想做的是写:
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);
}
}
Word 文档打印 HTML 标记“ <span style="bold">1</span>”而不是粗体“ 1 ”。
潇潇雨雨
相关分类