chetan Allipur

chetan Allipur

  • NA
  • 541
  • 166.4k

How to get the Numbered List Styles using word VSTO.

Jun 16 2017 3:31 AM
I want to get all Numbered list styles in word using VSTO code.
 
I want sample like this
 
 1. example ----List leve1
     a. hello------List level2
     b  demo ------List level3
         i. bye-------List level4
         ii. hi 
 
2. Example1
    a.  hello1
         i. bye1 
 
Above sample  format I want .
 
 Here is my code
 
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application app = Globals.ThisAddIn.Application;
app.Visible = true;
// whatever is selected will be turned into a numbered list.
object n = 1;
ListTemplate template =
app.ListGalleries[WdListGalleryType.wdOutlineNumberGallery].ListTemplates.get_Item(ref n);
Microsoft.Office.Interop.Word.ListLevel level = template.ListLevels[1];
level.NumberFormat = "%1.";
level.TrailingCharacter = WdTrailingCharacter.wdTrailingTab;
level.NumberStyle = WdListNumberStyle.wdListNumberStyleLowercaseLetter;
level.NumberPosition = app.InchesToPoints(0.25f);
level.Alignment = WdListLevelAlignment.wdListLevelAlignLeft;
level.TextPosition = app.InchesToPoints(0.25f);
level.TabPosition = (float)WdConstants.wdUndefined;
level.ResetOnHigher = 0;
level.StartAt = 1;
level.LinkedStyle = "";
template.Name = "";
object bContinuePrevList = true;
object applyTo = WdListApplyTo.wdListApplyToSelection;
object defBehavior = WdDefaultListBehavior.wdWord10ListBehavior;
app.Selection.Range.ListFormat.ApplyListTemplateWithLevel(
template, ref bContinuePrevList,
ref applyTo, ref defBehavior, ref missing);
 
 
 

Answers (2)