We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add heading numbers in word

how to add heading numbers in Word document ?

Hi Gregory,

Thanks for your inquiry. Following code example creates a sample document that exercises all outline headings list templates. Hope this helps you.


Document
doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.OutlineHeadingsArticleSection);

AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 1");

list = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);

AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 2");

builder.InsertBreak(BreakType.PageBreak);

list = doc.Lists.Add(ListTemplate.OutlineHeadingsNumbers);

AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 3");

list = doc.Lists.Add(ListTemplate.OutlineHeadingsChapter);

AddOutlineHeadingParagraphs(builder, list, "Aspose.Words Outline 4");

builder.Document.Save(MyDir + "Lists.OutlineHeadingTemplates Out.doc");

private static void AddOutlineHeadingParagraphs(DocumentBuilder builder, Aspose.Words.Lists.List list, string title)

{

builder.ParagraphFormat.ClearFormatting();

builder.Writeln(title);

for (int i = 0; i < 9; i++)

{

builder.ListFormat.List = list;

builder.ListFormat.ListLevelNumber = i;

string styleName = "Heading " + (i + 1).ToString();

builder.ParagraphFormat.StyleName = styleName;

builder.Writeln(styleName);

}

builder.ListFormat.RemoveNumbers();

}

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:DoNotShowPropertyChanges/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.