Search code examples
c#visual-studioms-wordmulti-level

Get Paragraph Number Format Text Applied by MultiLevel List


I am creating a Microsoft Word add-in using Visual Studio and C#. The add-in needs to be able to get the "number format text" (not sure if this is the correct terminology) applied by a Multi-level list. For example, a document using the MS Word default Heading styles applied to paragraphs also has a multi-level list applied which automatically numbers the paragraphs with Headings and adds the text "Article " to paragraphs with Heading 1, and applies the text "Section " to paragraphs with Heading 2. The end result is Article 1, Section 1.01, Section 1.02, Section 1.03, Article 2, Section 2.01, etc. The add-in needs to get the "Article 1", or "Section 1.01", etc..

I have tried various properties and methods of Range.Listformat, Range.ListParagrphs, Range.ListStyle, Range.ParagraphStyle, Paragraph.Format, and Paragraph.OutlineLevel but haven't found it yet. Range.ListFormat.ListLevelNumber gives the level as an integer, but not the text and exact paragraph number I am looking for. Does anyone out there know how to get that info? Thanks!

I read these and other but couldn't find what I'm looking for:

how to read multi level list numbers in ms word(word object model)?

Creating a multi-level bullet list with Word.Interop


Solution

  • To get the literal string for any paragraph's numbered list use

    TheParagraph.Range.ListFormat.ListString;