3

積み上げてもいいのかなと思ってRunPropertiesいたRun

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);

この場合、太字のテキストのみが表示され、下線は表示されません。

助けてください

4

1 に答える 1

4

私はあなたの例を試しましたが、実際には太字で下線を引いていませんでした。私はそれを少し処理し、これで終了しました:

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しただけでうまくいきました。

于 2012-08-05T20:22:38.850 に答える