dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.21k stars 477 forks source link

When using `patchDocument()` the custom numbering flow doesn't work. #2088

Open martijn10kb opened 1 year ago

martijn10kb commented 1 year ago

When using patchDocument() the custom numbering flow doesn't work. Or if it's possible where would we insert the INumberingOptions object? When trying to open a docx that has been generated that has custom numbering it fails to open.

Expect that I can somewhere insert this and use

import { AlignmentType, convertInchesToTwip, INumberingOptions, LevelFormat } from 'docx';

export const CHECKLIST_NUMBERING = 'checklist-numbering';

const numbering: INumberingOptions = {
  config: [
    {
      reference: CHECKLIST_NUMBERING,
      levels: [
        {
          level: 0,
          format: LevelFormat.BULLET,
          text: '⬜',
          alignment: AlignmentType.START,
#         style: {},
        },
        {
          level: 1,
          format: LevelFormat.BULLET,
          text: '✅',
          alignment: AlignmentType.START,
#         style: {},
        },
      ],
    },
  ],
};

export default numbering;

And then reference it like so: import { CHECKLIST_NUMBERING } from '../numbering';

const bulletStyle = styles.isChecklist
      ? { numbering: { level: isChecked ? 1 : 0, reference: CHECKLIST_NUMBERING } }
      : { bullet: { level: 0 } };
yarosalvpp commented 6 months ago

Same thing, trying to figure out how to make numbering paragraphs patching document

lcampanis commented 5 months ago

This is required, not possible to do at the moment...

valentindoering commented 2 months ago

I am even unable to insert a simple bullet point using patchDocument. When the document is opened in Libre Office or Google Docs, the bullet point appears as plain text instead of as a bullet point.

const updatedDocBuffer = await patchDocument(docBuffer, {
  patches: {
      placeholder: {
          type: PatchType.DOCUMENT,
          children: [ new Paragraph({ text: "Bullet point content", bullet: { level: 0 }} ],
      }
})

Are you experiencing similar issues? @lcampanis @yarosalvpp @martijn10kb