我试过你的例子,确实它只对我来说是粗体而不是下划线。我做了一点工作,最终得到了这个:
using (WordprocessingDocument doc = WordprocessingDocument.Open(destFileName, true))
{
Run run = new Run();
RunProperties runProperties = new RunProperties();
runProperties.AppendChild<Underline>(new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single });
runProperties.AppendChild<Bold>(new Bold());
run.AppendChild<RunProperties>(runProperties);
run.AppendChild(new Text("test"));
//Note: I had to create a paragraph element to place the run into.
Paragraph p = new Paragraph();
p.AppendChild(run);
doc.MainDocumentPart.Document.Body.AppendChild(p);
}
基本上,这改变了:
new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single }
您必须指定所需的下划线类型,而不仅仅是将其留给 Underline 类的构造函数。我刚刚指定Single
,它对我有用。