Search code examples
c#ms-wordoffice-interop

How can I know if a Word list is a bullet list or a numeric list?


I am reading a word document (converting it to HTML) and want to know what type each paragraph is (at least that's the way I think I want to do it like).

My code looks like this

Application application = new Application();
var doc = application.Documents.Open("D:\\myDoc.docx");

for (int i = 0; i < doc.Paragraphs.Count; i++)
{
     Console.WriteLine($"{doc.Paragraphs[i + 1].Range.ParagraphStyle.NameLocal}");
}

This outputs Header 1, Normal and List Paragraph for instance. So my question. I can't see if List Paragraph is a bullet list or a numeric list. Question, How can I know what type the list is of?


Solution

  • Use Range.ListFormat.ListType which can have the following values:

    // Summary:
    //     Specifies a type of list.
    public enum WdListType
    {
        // Summary:
        //     List with no bullets, numbering, or outlining.
        wdListNoNumbering = 0,
        //
        // Summary:
        //     ListNum fields that can be used in the body of a paragraph.
        wdListListNumOnly = 1,
        //
        // Summary:
        //     Bulleted list.
        wdListBullet = 2,
        //
        // Summary:
        //     Simple numeric list.
        wdListSimpleNumbering = 3,
        //
        // Summary:
        //     Outlined list.
        wdListOutlineNumbering = 4,
        //
        // Summary:
        //     Mixed numeric list.
        wdListMixedNumbering = 5,
        //
        // Summary:
        //     Picture bulleted list.
        wdListPictureBullet = 6,
    }