Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo3 numbered lists loses last item, no apparent indentation #387

Closed
dil-wainstead opened this issue Aug 26, 2019 · 3 comments · Fixed by #447
Closed

demo3 numbered lists loses last item, no apparent indentation #387

dil-wainstead opened this issue Aug 26, 2019 · 3 comments · Fixed by #447

Comments

@dil-wainstead
Copy link
Contributor

dil-wainstead commented Aug 26, 2019

I'm using the latest copy of demo3.ts; compiling it from scratch like so:

npx tsc demo3.ts
node demo3.js
open My*docx

While the example builds a numbered list of:

  1. upperRoman
  2. decimal
  3. lowerLetter

the resulting docx file renders like this:

Screen Shot 2019-08-26 at 8 30 06 AM

where the "Yeah boi" for the numbered list doesn't show up; the indentation appears to not work either.

@dil-wainstead dil-wainstead changed the title demo3 numbered lists don't change type (all come out numeric) demo3 numbered lists loses last item, no apparent indentation Aug 26, 2019
@dil-wainstead
Copy link
Contributor Author

dil-wainstead commented Aug 26, 2019

In this modified version of demo3, I've added another level ("upperLetter"), and added some more children at different levels:

// Numbering and bullet points example
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
//import { Document, Numbering, Packer, Paragraph } from "../build";
import { Document, Numbering, Packer, Paragraph } from "docx";

const doc = new Document();

//const numbering = new Numbering();
const numbering = doc.Numbering;

const abstractNum = numbering.createAbstractNumbering();
abstractNum.createLevel(0, "upperRoman", "%1", "start").indent({ left: 720, hanging: 260 });
abstractNum.createLevel(1, "decimal", "%2.", "start").indent({ left: 1440, hanging: 980 });
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").indent({ left: 2160, hanging: 1700 });
abstractNum.createLevel(3, "upperLetter", "%4)", "start").indent({ left: 2880, hanging: 2420 });

const concrete = numbering.createConcreteNumbering(abstractNum);

doc.addSection({
    children: [
        new Paragraph({
            text: "Hey you",
            numbering: {
                num: concrete,
                level: 0,
            },
        }),
        new Paragraph({
            text: "What's up fam",
            numbering: {
                num: concrete,
                level: 1,
            },
        }),
        new Paragraph({
            text: "Hello World 2",
            numbering: {
                num: concrete,
                level: 1,
            },
        }),
        new Paragraph({
            text: "Yeah boi",
            numbering: {
                num: concrete,
                level: 2,
            },
        }),
        new Paragraph({
            text: "101 MSXFM",
            numbering: {
                num: concrete,
                level: 3,
            },
        }),
        new Paragraph({
            text: "back to level 1",
            numbering: {
                num: concrete,
                level: 1,
            },
        }),
        new Paragraph({
            text: "back to level 0",
            numbering: {
                num: concrete,
                level: 0,
            },
        }),
    ],
});

Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("demo3.2.docx", buffer);
});

The output has the items of the lists indented, but not the numbers themselves:

Screen Shot 2019-08-26 at 9 36 04 AM

Note that I made this change, which I saw in another ticket:

//const numbering = new Numbering();
const numbering = doc.Numbering;

which makes the different numbering styles work; without this change, all the numbering is the same:

Screen Shot 2019-08-26 at 9 40 50 AM

@dolanmiu
Copy link
Owner

This is now fixed with #447

An example, which uses your modified example above is here:

https://github.com/dolanmiu/docx/blob/master/demo/3-numbering-and-bullet-points.ts

@lancejpollard
Copy link

lancejpollard commented Feb 11, 2024

@dolanmiu this isn't working for me, your demo isn't working either. Any ideas? #2590. Can you hint at what needs to be fixed/changed in the XML or whatnot? I can take a stab at it.

Mac Pages

Screenshot 2024-02-11 at 12 40 35 PM

Google Docs

Screenshot 2024-02-11 at 12 41 40 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants