C#でopenxml sdk 2を使用して段落スタイルを作成し、それを段落に適用すると、すべてが正しくなり、問題なく実行されます。
しかし、以下のコードでは、文字スタイルを作成して実行に適用しても、ドキュメントの実行は変更されません。
以下のコードは、ドキュメントのスタイル部分にスタイルを作成して保存します。
StyleDefinitionsPart stylePart = mainPart.AddNewPart<StyleDefinitionsPart>();
Style style = new Style()
{
Type = StyleValues.Character,
CustomStyle = true,
StyleId = "CharacterStyle1"
};
LinkedStyle linkedStyle1 = new LinkedStyle() { Val = "LinkedStyle" };
style.Append(linkedStyle1);
style.Append(new Name() { Val = "CharacterStyle1" });
StyleRunProperties styleRunProperties1 = new StyleRunProperties();
Color color = new Color() { Val = "FF0000" };
RunFonts font1 = new RunFonts() { ComplexScript = "Tahoma" };
styleRunProperties1.Append(color);
styleRunProperties1.Append(font1);
styleRunProperties1.Append(new Bold());
styleRunProperties1.Append(new FontSize() { Val = "48" });
style.Append(styleRunProperties1);
stylePart.Styles = new Styles();
stylePart.Styles.Append(style);
以下のコードは、実行にスタイルを適用するために私が書いたものです。
Paragraph heading = new Paragraph();
ParagraphProperties headingPPr = new ParagraphProperties();
heading.Append(headingPPr);
Run run1 = new Run();
Text textRun1 = new Text("THIS IS TEST RUN 1");
run1.Append(textRun1);
RunProperties rprRun1 = new RunProperties {RunStyle = new RunStyle() {Val = "CharacterStyle1"}};
heading.Append(run1);
body.Append(heading);
そして、これらはdocument.xmlの出力コードです:
<?xml version="1.0" encoding="utf-8"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr />
<w:r w:rsidRPr="009531B2">
<w:t>THIS IS TEST RUN 1</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
スタイルが私のランニングに適用されませんでした!
最後に、これは出力されたドキュメントを開いたときのスタイル ギャラリーのスクリーン ショットです。この画像は、スタイルがドキュメントに正常に追加されたことを示していますが、実行には適用されませんでした。
文字スタイルを実行に適用するにはどうすればよいですか?