docx: Numbering start from number doesn't work

My greetings 😃 This list men to to start from 50, but it does not. Do I do something wrong or feature got corrupted? Tested on 6.0.1, 6.0.3 Based on: https://github.com/dolanmiu/docx/blob/7acd9e1/src/file/numbering/level.ts#L89 image

const fs = require('fs');
const { Document, Packer, Paragraph, PageNumberFormat} = require('docx');

const doc = new Document({
  numbering:{
    config:[{
      reference: 'ref1',
      levels: [
        {
          level: 0,
          format: PageNumberFormat.DECIMAL,
          text: '%1)',
          start: 50,
        }
      ],
    }]
  },
  sections: [{
    children: [
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
      new Paragraph({
        text: "REF1 - inst:0 - lvl:0",
        numbering : {
          reference: 'ref1',
          instance: 0,
          level: 0,
        }
      }),
    ],
  }]
});

// Used to export the file into a .docx file
Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("start_numbering.docx", buffer);
});

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@TheDarkStrix Can you create some easy example for me to run to illustrate the problem? (Just like I did in the issue description) This way it would be a little easier to understand what exactly doesn’t work.

I would close the issue, since the first stated problem solved by merged https://github.com/dolanmiu/docx/pull/1057 @tiejunhu I think it worth opening new issue if your problem persists. Or you can reopen if you like…

While thinking of implementing testing of that case, came into conclusion that .spec.ts way is not applicable (unfortunately) since the numbering happens on the Word side. I’ve added some demo into pull request instead.

interesting.

How would you suggest to fix this?

Currently, I create different abstractNumbering for all numbering that’s not started from 1

so it seems to me that overrides must be conditional, and is required when the user wants to restart numbered lists, but shouldn’t be included by default

I believe that would be a proper fix.

I encountered same issue. I dig some and found the w:start was properly set but got overrided by this : https://github.com/dolanmiu/docx/blob/9048f8f2713a88c96a49a477e89051ae27724079/src/file/numbering/numbering.ts#L201-L203

The generated docx file reflected the same observation.

it seems not reasonable to override the numbering.

@dolanmiu would you check why there’s an override ?