在Word软件中内嵌了多种默认的样式,如标题、标题一、副标题、强调等很多文本段落样式,同样地
Aspose.Words控件也内嵌了这种样式,开发人员可以使用代码轻松地为Word文档插入带样式的文本或段落,或者对Word中已有的段落进行格式样式的设置,下面的代码主要用于对新的Word文档插入一段“标题一”样式的文本,具体可以参考下面的代码:
Document doc = new Document();
// Insert two sections with some text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Section 1 Unprotected hadadkajhdjkad");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.BodyText;
// Call the method below to update the TOC.
doc.UpdateFields();
builder.Document.Save("style.doc");