-
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Numbered lists - Add parent number in sub number | ||
// Import from 'docx' rather than '../build' if you install from npm | ||
import * as fs from "fs"; | ||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph } from "../build"; | ||
|
||
const doc = new Document({ | ||
numbering: { | ||
config: [ | ||
{ | ||
levels: [ | ||
{ | ||
level: 0, | ||
format: "decimal", | ||
text: "%1", | ||
alignment: AlignmentType.START, | ||
style: { | ||
paragraph: { | ||
indent: { left: 720, hanging: 260 }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
level: 1, | ||
format: "decimal", | ||
text: "%1.%2", | ||
alignment: AlignmentType.START, | ||
style: { | ||
paragraph: { | ||
indent: { left: 1.25 * 720, hanging: 1.25 * 260 }, | ||
}, | ||
run: { | ||
bold: true, | ||
size: 18, | ||
font: "Times New Roman", | ||
}, | ||
}, | ||
}, | ||
], | ||
reference: "my-number-numbering-reference", | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
doc.addSection({ | ||
children: [ | ||
new Paragraph({ | ||
text: "How to make cake", | ||
heading: HeadingLevel.HEADING_1, | ||
}), | ||
new Paragraph({ | ||
text: "Step 1 - Add sugar", | ||
numbering: { | ||
reference: "my-number-numbering-reference", | ||
level: 0, | ||
}, | ||
}), | ||
new Paragraph({ | ||
text: "Step 2 - Add wheat", | ||
numbering: { | ||
reference: "my-number-numbering-reference", | ||
level: 0, | ||
}, | ||
}), | ||
new Paragraph({ | ||
text: "Step 2a - Stir the wheat in a circle", | ||
numbering: { | ||
reference: "my-number-numbering-reference", | ||
level: 1, | ||
}, | ||
}), | ||
new Paragraph({ | ||
text: "Step 3 - Put in oven", | ||
numbering: { | ||
reference: "my-number-numbering-reference", | ||
level: 0, | ||
}, | ||
}), | ||
new Paragraph({ | ||
text: "How to make cake", | ||
heading: HeadingLevel.HEADING_1, | ||
}), | ||
], | ||
}); | ||
|
||
Packer.toBuffer(doc).then((buffer) => { | ||
fs.writeFileSync("My Document.docx", buffer); | ||
}); |