如何使用 OpenXml.Wordprocessing 和 C# 在 MS Word 中创建自定义样式链接(段落和字符)

How to create custom style Linked (paragraph and character) in MS Word using OpenXml.Wordprocessing and C#

如何使用 OpenXml.Wordprocessing 和 C# 在 MS Word 中创建自定义样式链接(段落和字符):

我想更改这段代码以创建链接样式而不是字符样式:

StyleDefinitionsPart part = document.MainDocumentPart.StyleDefinitionsPart;

Styles styles = part.Styles;
Style style = new Style()
{
    StyleId = "somestyle",
    CustomStyle = true
};
style.Append(new StyleName() { Val = "somestyle" });
style.Append(new BasedOn() { Val = "Normal" });
style.Append(new NextParagraphStyle() { Val = "Normal" });
style.Append(new UIPriority() { Val = 900 });

StyleRunProperties styleRunProperties = new StyleRunProperties();
Color color1 = new Color() { Val = "somecolor" };
FontSize fontSize1 = new FontSize();
fontSize1.Val = new StringValue(customStyle.FontSize);

styleRunProperties.Append(color1);
styleRunProperties.Append(fontSize1);
style.Append(styleRunProperties);
styles.Append(style);

有什么想法吗?

Open XML SDK 生产力工具推荐非常有用。解决方案是创建两种样式 - 一种用于段落,一种用于字符,并通过 LinkedStyle 属性将它们链接起来。