question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Numbering levels do not apply when called as instance methods (static required)

See original GitHub issue

Numbering does not appear to be responding to what is defined in createLevel method. See the screenshot below, which is generated by the code that follows.

image

Adjusting the indent levels or list type (e.g. upperRoman vs decimal) in createLevel() has no effect. I tested this in three different ways, commented as OPTION 1, OPTION 2, OPTION 3 in the code below. In each option the output looks the same.

var fs = require('fs')
var docx = require('docx');

const doc = new docx.Document();

const numbering = new docx.Numbering();

const abstractNum = numbering.createAbstractNumbering();

// OPTION 1: No createLevel

// OPTION 2:
// abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new docx.Indent(360, 130));
// abstractNum.createLevel(1, "decimal", "%2", "start").addParagraphProperty(new docx.Indent(1200, 3000));
// abstractNum.createLevel(2, "lowerLetter", "%3	", "start").addParagraphProperty(new docx.Indent(4000, 5000));

// OPTION 3;
// abstractNum.createLevel(0, "upperRoman", "%1", "start").indent({ left: 360, hanging: 130 });
// abstractNum.createLevel(1, "decimal", "%1.%2.", "start").indent({ left: 1200, hanging: 3000 });
// abstractNum.createLevel(2, "lowerLetter", "%3)", "start").indent({ left: 4000, hanging: 5000 });

const concrete = numbering.createConcreteNumbering(abstractNum);

doc.addSection({
	children: [
		new docx.Paragraph({ text: "Item 1", numbering: { num: concrete, level: 0 }}),
		new docx.Paragraph({ text: "Item 1.1", numbering: { num: concrete, level: 1 }}),
		new docx.Paragraph({ text: "Item 1.2", numbering: { num: concrete, level: 1 }}),
		new docx.Paragraph({ text: "Item 1.2.1", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.2.2", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.2.3", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.3", numbering: { num: concrete, level: 1 }}),
		new docx.Paragraph({ text: "Item 2", numbering: { num: concrete, level: 0 }}),
		new docx.Paragraph({ text: "Item 3", numbering: { num: concrete, level: 0 }}),
	],
});

docx.Packer.toBuffer(doc).then((buffer) => {
	fs.writeFileSync("docx-simple-num.docx", buffer);
});

Using docx version 5.0.0-rc5 and Node v10.16.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jamesmontalvo3commented, Sep 4, 2019

EDIT: This comment has been moved to a separate issue, #396.

Perhaps this is a separate issue, but in the interest of not flooding the issues list I tack it on here: paragraphs with numbering defined do not respond to style. See the example below, followed by the code that generated it.

image

Code:

var fs = require('fs')
var docx = require('docx');

const doc = new docx.Document();

doc.Styles.createParagraphStyle("numberdemo", "Number Demo")
	.basedOn("Normal")
	.next("Normal")
	.font("Arial")
	.quickFormat()
	.size(40);

const numbering = new docx.Numbering();

const abstractNum = numbering.createAbstractNumbering();

abstractNum.createLevel(0, "upperRoman", "%1", "start").indent({ left: 360, hanging: 130 });
abstractNum.createLevel(1, "decimal", "%1.%2.", "start").indent({ left: 1200, hanging: 3000 });
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").indent({ left: 4000, hanging: 5000 });

const concrete = numbering.createConcreteNumbering(abstractNum);

doc.addSection({
	children: [
		new docx.Paragraph({ text: "No numbering", style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering, no style" }),
		new docx.Paragraph({ text: "Item 1", numbering: { num: concrete, level: 0 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.1", numbering: { num: concrete, level: 1 }}),
		new docx.Paragraph({ text: "Item 1.2", numbering: { num: concrete, level: 1 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.2.1", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.2.2", numbering: { num: concrete, level: 2 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.2.3", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.3", numbering: { num: concrete, level: 1 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 2", numbering: { num: concrete, level: 0 }}),
		new docx.Paragraph({ text: "Item 3", numbering: { num: concrete, level: 0 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering 2", style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering, no style 2" })
	],
});

docx.Packer.toBuffer(doc).then((buffer) => {
	fs.writeFileSync("docx-simple-num.docx", buffer);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python's Instance, Class, and Static Methods Demystified
This tutorial helps demystify what's behind class, static, and instance methods in Python.
Read more >
Static methods vs Instance methods in Java - GeeksforGeeks
Instance method (s) belong to the Object of the class, not to the class i.e. they can be called after creating the Object...
Read more >
4. Static Variables and Static Methods - Essential ActionScript ...
Static methods have two limitations that instance methods do not. First, a class method cannot use the this keyword. Second, a static method...
Read more >
Python Methods: Instance, Static and Class - The Teclado Blog
In this blog post we are going to explain what types of methods exist, how they work, and how they are different from...
Read more >
Performance of static methods vs instance methods
When keeping state is not a concern (no fields or properties are required), is it always better to use a static class? Where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found