1
votes

I'm creating an application that is working with word automation. I'm using visual studio 2010, Microsoft word 2010 and working with interop.

I got the following 3 styles in my word document.

enter image description here

As you can see I have formatted the styles so that they get on their own level when doing numbering. What I would like the application to do is to open an already existing document with numbered bullets (the app can do that) and then add some more (see picture).

enter image description here

So far I've tried this but it doesn't seem to follow the format that I've put in the style manually.

    public void insertTextHeading(Word.Document document, string bookmark, string text, int fontSize, string headingType, int listNumber, int bulletLevel)
    {
        var start = document.Bookmarks[bookmark].Start;
        var end = document.Bookmarks[bookmark].End;
        Word.Range range = document.Range(start, end);

        //The text design
        range.Font.Name = "Verdana";
        range.Font.Size = fontSize;
        range.set_Style(headingType);

        object n = listNumber;
        Word.ListTemplate template =
            document.Application.ListGalleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates.get_Item(ref n);

        object bContinuePrevList = true;
        object applyTo = Word.WdListApplyTo.wdListApplyToSelection;
        object defBehavior = Word.WdDefaultListBehavior.wdWord10ListBehavior;
        object missing = System.Reflection.Missing.Value;

        range.ListFormat.ApplyListTemplateWithLevel(
        template, ref bContinuePrevList,
        ref applyTo, ref defBehavior, ref missing);
        range.Text = text;
    }
1

1 Answers

1
votes

Sometimes it turns out that the answer to your own question is that you're an idiot. After a couple of hours I decided to debug every line of code I had and it turns out that the styles I've added manually to the word template creates the numbering itself. So I've tried to add the numbering by code when all I had to do was to tell the text to be inserted as the style I wanted.