繁体   English   中英

使用OpenXML SDK 2.0在运行时累积RunProperties

[英]Cumulate RunProperties on Run with OpenXML SDK 2.0

我想知道我是否可以在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);

在这种情况下,我只有粗体文字而不是下划线。

请帮忙

我尝试了你的例子,事实上它只对我做了大胆而没有强调。 我工作了一点,最后得到了这个:

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 ,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM