I want like this sub heading Increment.
1. Chapter One
1.1 Chapter One Section One
1.1.1 Chapter One Section One Subsection One
1.1.2 Chapter One Section One Subsection Two
2. Chapter Two
2.1 Chapter Two Section 1
3. Chapter Three
3.1 Chapter Three Section One
But I am getting like
1. Chapter One
1.1 Chapter One Section One
1.1.1 Chapter One Section One Subsection One
1.1.2 Chapter One Section One Subsection Two
2. Chapter Two
1.2 Chapter Two Section 1
3. Chapter Three
1.3 Chapter Three Section One
Here is my code.
Microsoft.Office.Interop.Word.Application app = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Word.Document doc1 = app.ActiveDocument;
string sHeadingNm = doc1.Styles[WdBuiltinStyle.wdStyleHeading1].NameLocal;
Microsoft.Office.Interop.Word.Style style = null;
ListTemplate template = null;
doc1.UpdateStyles();
app.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].Reset(2);
template = app.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates[2];
Microsoft.Office.Interop.Word.ListLevel level = template.ListLevels[1];
if (level.NumberStyle == WdListNumberStyle.wdListNumberStyleBullet)
{
level.NumberStyle = WdListNumberStyle.wdListNumberStyleNone;
}
level.NumberFormat = sPrefix + "%1.";
level.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
level.NumberStyle = WdListNumberStyle.wdListNumberStyleArabic;
level.NumberPosition = app.InchesToPoints(0f);
level.Alignment = WdListLevelAlignment.wdListLevelAlignLeft;
level.TextPosition = app.InchesToPoints((float)nHeadIndent);
level.TabPosition = app.InchesToPoints((float)nHeadIndent);
level.ResetOnHigher = 0;
level.StartAt = int.Parse(sHead1No);
//level.LinkedStyle = sHeadingNm + "1";
//Microsoft.Office.Interop.Word.Style style = doc1.Styles["Heading " + 1];
style = doc1.Styles["Heading " + 1];
style.LinkToListTemplate(template, 1);
This code I am applicale for Heading 1 to 5.
Please anyone help me. Send me the code back.
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
chetan AllipurPosted Jun 23, 2017, 4:38 AM
Manikandan MurugesanPosted Jun 23, 2017, 3:36 AM