Files
docx-js/demo/29-numbered-lists.ts

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-02-26 22:20:20 +00:00
// Numbered lists
// Import from 'docx' rather than '../build' if you install from npm
2018-09-26 17:47:17 +03:00
import * as fs from "fs";
2019-07-31 08:48:02 +01:00
import { Document, Numbering, Packer, Paragraph } from "../build";
2018-09-26 17:47:17 +03:00
const doc = new Document();
const numbering = new Numbering();
const abstractNum = numbering.createAbstractNumbering();
2019-07-31 08:48:02 +01:00
abstractNum.createLevel(0, "upperRoman", "%1", "start").indent({ left: 720, hanging: 260 });
2018-09-26 17:47:17 +03:00
const concrete = numbering.createConcreteNumbering(abstractNum);
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [
new Paragraph({
text: "line with contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: true,
spacing: {
before: 200,
},
}),
new Paragraph({
text: "line with contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: true,
spacing: {
before: 200,
},
}),
new Paragraph({
text: "line without contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: false,
spacing: {
before: 200,
},
}),
new Paragraph({
text: "line without contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: false,
spacing: {
before: 200,
},
}),
],
2019-06-17 01:51:57 +01:00
});
2018-09-26 17:47:17 +03:00
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
2019-01-04 00:11:50 +00:00
});