1

I'm using NovaCode and trying to fill a list in a document at a specific paragraph. I am able to build the list but the numbering doesn't go further than 1.

example:

1. Number one
   Number two
   Number three
   Number four

I have tried \r, \n and \r\n ( and a bunch of other ), but they all seem to just do "shift+enter" instead of an actual enter. The latter continues the numbering.

Is there a way to increment this using NovaCode? You can create lists with NovaCode but it's impossible to insert them into paragraphs.. ( I'm replacing fields in an existing document )

Code:

            VariableValue listorderlinenames = factory.Variables.FirstOrDefault(x => x.Name == "[Offer.Orderline.OrderLineNames]");
            Paragraph foundlistorderlinenames = factory.Document.Paragraphs.Where(x => x.Text.IndexOf(listorderlinenames.Name) >= 0).FirstOrDefault();
            foreach (Orderline orderline in offer.OrderLines)
            {
                foundlistorderlinenames.IndentationBefore = 3;
                foundlistorderlinenames.Append(counter + 1 + ". " + orderline.Name);
                foundlistorderlinenames.Append("\r\n");
            }

This is the ugly way I'm doing it, making a fake list.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Carlove
  • 429
  • 1
  • 4
  • 15
  • Possibly related: https://stackoverflow.com/questions/28213830/c-sharp-docx-inserting-new-numbered-list-continues-numbering – Stefan Dec 04 '18 at 11:04
  • Have you tried to use 'Environment.NewLine' ? – John Antony Daniel Nolan Dec 04 '18 at 11:10
  • The issue is, the insertion of a new bullet/number on pressing enter is a feature of the *Word application*, not something inherent to the document (format). – Damien_The_Unbeliever Dec 04 '18 at 11:14
  • @JohnAntonyDanielNolan According to the documentation 'Environment.NewLine' does a "\r\n", which I'm doing right now. It seems like I can't insert an enter. – Carlove Dec 04 '18 at 11:15
  • I'm not familiar with nova code, but do have knowledge of the underlying Word Open XML. Each "List" format in a document has a "list template". A paragraph must be associated with the list template in order for it to "do" automatic numbering in a list. Simplest is if the list template is assigned to a particular Style, then applying that style to a paragraph also applies the numbering. If you look at the underlying Word Open XML the information should be at the Paragraph Property level (pPr), so it can't be appended to a paragraph, it's lower in the hierarchy. – Cindy Meister Dec 04 '18 at 12:26

1 Answers1

0

maybe this:

List list = doc.AddList("item 1", 0, ListItemType.Numbered);
simonecosci
  • 1,194
  • 7
  • 13
  • The problem is that a list can't be appended to a Paragraph. I look up the paragraph (by merge-field) and then append whatever needs to be appended ( like a table ). – Carlove Dec 04 '18 at 11:02