簡體   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