Files
docx-js/demo/demo29.ts

70 lines
1.5 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";
import { Document, Indent, Numbering, Packer, Paragraph } from "../build";
const doc = new Document();
const numbering = new Numbering();
const abstractNum = numbering.createAbstractNumbering();
2019-06-25 23:17:56 +01:00
abstractNum.createLevel(0, "upperRoman", "%1", "start").addProperty(new Indent({ left: 720, hanging: 260 }));
2018-09-26 17:47:17 +03:00
const concrete = numbering.createConcreteNumbering(abstractNum);
2019-06-17 01:51:57 +01:00
const item1 = new Paragraph({
text: "line with contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: true,
spacing: {
before: 200,
},
});
const item2 = new Paragraph({
text: "line with contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: true,
spacing: {
before: 200,
},
});
const item3 = new Paragraph({
text: "line without contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: false,
spacing: {
before: 200,
},
});
const item4 = new Paragraph({
text: "line without contextual spacing",
numbering: {
num: concrete,
level: 0,
},
contextualSpacing: false,
spacing: {
before: 200,
},
});
2018-09-26 17:47:17 +03:00
2019-06-25 23:17:56 +01:00
doc.add(item1);
doc.add(item2);
doc.add(item3);
doc.add(item4);
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
});