[英]Cumulate RunProperties on Run with OpenXML SDK 2.0
I was wondering if I could cumulate RunProperties
on Run
我想知道我是否可以在
Run
上累积RunProperties
Run run = new Run(new Text("test"));
RunProperties runProperties = new RunProperties();
runProperties.AppendChild<Bold>(new Bold());
runProperties.AppendChild<Underline>(new Underline());
run.AppendChild<RunProperties>(runProperties);
In this case, I only got Bold text but not Underline. 在这种情况下,我只有粗体文字而不是下划线。
Please help 请帮忙
I tried your example and indeed it only did bold for me and not underline. 我尝试了你的例子,事实上它只对我做了大胆而没有强调。 I worked it a bit and ended up with this:
我工作了一点,最后得到了这个:
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);
}
Basically, this changed: 基本上,这改变了:
new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single }
You have to specify the type of underline you want and not just leave it up to the Underline class's constructor. 您必须指定所需的下划线类型,而不是将其留给Underline类的构造函数。 I just specified
Single
and it worked for me. 我刚刚指定了
Single
,它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.