C# Aspose Word adds a paragraph style and applies it to a paragraph

The following is a sample code for adding a paragraph style and applying it to a paragraph using Aspose Word in C#:

// 创建一个新的样式
Style style = doc.Styles.Add(StyleType.Paragraph, "MyStyle");

// 设置样式属性
style.Font.Name = "Arial";
style.Font.Size = 12;
style.Font.Color = Color.Blue;
style.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// 获取文档的第一个段落
Paragraph para = doc.FirstSection.Body.FirstParagraph;

// 应用样式到段落
para.ParagraphFormat.Style = style;

// 插入文本到段落
para.AppendText("Hello World!");

In the above code a new paragraph style named "MyStyle" is created and some properties are set such as font, font size, color and alignment. Then, we get the first paragraph of the document and apply the style to it. Finally, we insert some text into the paragraph.

Guess you like

Origin blog.csdn.net/QH2107/article/details/129989208
Recommended