Merge pull request #840 from dolanmiu/feat/declarative-add-section

Make .addSection fully declarative
This commit is contained in:
Dolan
2021-03-19 23:52:15 +00:00
committed by GitHub
86 changed files with 3367 additions and 3276 deletions

8
.nycrc
View File

@ -1,9 +1,9 @@
{ {
"check-coverage": true, "check-coverage": true,
"lines": 98.79, "lines": 98.86,
"functions": 97.54, "functions": 97.86,
"branches": 95.64, "branches": 95.86,
"statements": 98.8, "statements": 98.86,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build"; import { Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -22,6 +22,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -129,9 +129,9 @@ const achievements = [
class DocumentCreator { class DocumentCreator {
// tslint:disable-next-line: typedef // tslint:disable-next-line: typedef
public create([experiences, educations, skills, achivements]): Document { public create([experiences, educations, skills, achivements]): Document {
const document = new Document(); const document = new Document({
sections: [
document.addSection({ {
children: [ children: [
new Paragraph({ new Paragraph({
text: "Dolan Miu", text: "Dolan Miu",
@ -143,7 +143,10 @@ class DocumentCreator {
.map((education) => { .map((education) => {
const arr: Paragraph[] = []; const arr: Paragraph[] = [];
arr.push( arr.push(
this.createInstitutionHeader(education.schoolName, `${education.startDate.year} - ${education.endDate.year}`), this.createInstitutionHeader(
education.schoolName,
`${education.startDate.year} - ${education.endDate.year}`,
),
); );
arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`)); arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
@ -190,10 +193,13 @@ class DocumentCreator {
), ),
new Paragraph("More references upon request"), new Paragraph("More references upon request"),
new Paragraph({ new Paragraph({
text: "This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.", text:
"This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
alignment: AlignmentType.CENTER, alignment: AlignmentType.CENTER,
}), }),
], ],
},
],
}); });
return document; return document;

View File

@ -17,6 +17,39 @@ import {
UnderlineType, UnderlineType,
} from "../build"; } from "../build";
const table = new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 1.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 2.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 3.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 4.")],
}),
],
}),
],
});
const doc = new Document({ const doc = new Document({
styles: { styles: {
default: { default: {
@ -124,48 +157,18 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
const table = new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 1.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 2.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 3.")],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Test cell 4.")],
}),
],
}),
],
});
doc.addSection({
properties: { properties: {
page: {
margin: {
top: 700, top: 700,
right: 700, right: 700,
bottom: 700, bottom: 700,
left: 700, left: 700,
}, },
},
},
footers: { footers: {
default: new Footer({ default: new Footer({
children: [ children: [
@ -258,6 +261,8 @@ doc.addSection({
style: "normalPara2", style: "normalPara2",
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, ImageRun, Packer, Paragraph } from "../build"; import { Document, ImageRun, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph("Hello World"), new Paragraph("Hello World"),
new Paragraph({ new Paragraph({
@ -53,6 +53,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -7,9 +7,8 @@ const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
const doc = new Document({ const doc = new Document({
title: "Title", title: "Title",
externalStyles: styles, externalStyles: styles,
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "Cool Heading Text", text: "Cool Heading Text",
@ -25,6 +24,8 @@ doc.addSection({
style: "MyFancyStyle", style: "MyFancyStyle",
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build"; import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: { properties: {
titlePage: true, titlePage: true,
}, },
@ -71,6 +71,8 @@ doc.addSection({
}), }),
new Paragraph("Second Page"), new Paragraph("Second Page"),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph } from "../build"; import { Document, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph("Hello World"), new Paragraph("Hello World"),
new Paragraph({ new Paragraph({
@ -13,6 +13,8 @@ doc.addSection({
pageBreakBefore: true, pageBreakBefore: true,
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,13 +3,20 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Footer, Header, Packer, PageNumber, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build"; import { Document, Footer, Header, Packer, PageNumber, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
}); },
{
doc.addSection({ properties: {
page: {
pageNumbers: {
start: 1,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: new Header({ default: new Header({
children: [new Paragraph("First Default Header on another page")], children: [new Paragraph("First Default Header on another page")],
@ -20,14 +27,21 @@ doc.addSection({
children: [new Paragraph("Footer on another page")], children: [new Paragraph("Footer on another page")],
}), }),
}, },
properties: {
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
children: [new Paragraph("hello")],
});
doc.addSection({ children: [new Paragraph("hello")],
},
{
properties: {
page: {
size: {
orientation: PageOrientation.LANDSCAPE,
},
pageNumbers: {
start: 1,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: new Header({ default: new Header({
children: [new Paragraph("Second Default Header on another page")], children: [new Paragraph("Second Default Header on another page")],
@ -38,37 +52,16 @@ doc.addSection({
children: [new Paragraph("Footer on another page")], children: [new Paragraph("Footer on another page")],
}), }),
}, },
size: {
orientation: PageOrientation.LANDSCAPE,
},
properties: {
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
children: [new Paragraph("hello in landscape")], children: [new Paragraph("hello in landscape")],
});
doc.addSection({
headers: {
default: new Header({
children: [
new Paragraph({
children: [
new TextRun({
children: ["Page number: ", PageNumber.CURRENT],
}),
],
}),
],
}),
}, },
{
properties: {
page: {
size: { size: {
orientation: PageOrientation.PORTRAIT, orientation: PageOrientation.PORTRAIT,
}, },
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")], },
}); },
doc.addSection({
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -82,18 +75,51 @@ doc.addSection({
], ],
}), }),
}, },
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")],
},
{
properties: { properties: {
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN, page: {
size: {
orientation: PageOrientation.PORTRAIT, orientation: PageOrientation.PORTRAIT,
}, },
pageNumbers: {
formatType: PageNumberFormat.UPPER_ROMAN,
},
},
},
headers: {
default: new Header({
children: [
new Paragraph({
children: [
new TextRun({
children: ["Page number: ", PageNumber.CURRENT],
}),
],
}),
],
}),
},
children: [ children: [
new Paragraph( new Paragraph(
"Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.", "Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.",
), ),
], ],
}); },
{
doc.addSection({ properties: {
page: {
size: {
orientation: PageOrientation.PORTRAIT,
},
pageNumbers: {
start: 25,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -107,15 +133,12 @@ doc.addSection({
], ],
}), }),
}, },
size: {
orientation: PageOrientation.PORTRAIT,
},
properties: {
pageNumberFormatType: PageNumberFormat.DECIMAL,
pageNumberStart: 25,
},
children: [ children: [
new Paragraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section."), new Paragraph(
"Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section.",
),
],
},
], ],
}); });

View File

@ -12,9 +12,8 @@ const doc = new Document({
5: { children: [new Paragraph("Test1")] }, 5: { children: [new Paragraph("Test1")] },
6: { children: [new Paragraph("My amazing reference1")] }, 6: { children: [new Paragraph("My amazing reference1")] },
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -30,9 +29,8 @@ doc.addSection({
children: [new TextRun("Hello World"), new FootnoteReferenceRun(3)], children: [new TextRun("Hello World"), new FootnoteReferenceRun(3)],
}), }),
], ],
}); },
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -48,6 +46,8 @@ doc.addSection({
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)], children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,11 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, ImageRun, Packer, Paragraph } from "../build"; import { Document, ImageRun, Packer, Paragraph } from "../build";
const doc = new Document();
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx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K6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
doc.addSection({ const doc = new Document({
sections: [
{
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -21,6 +21,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "../build"; import { Document, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -21,6 +21,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBase64String(doc).then((str) => { Packer.toBase64String(doc).then((str) => {

View File

@ -99,9 +99,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "Test heading1, bold and italicized", text: "Test heading1, bold and italicized",
@ -184,6 +183,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
const table = new Table({ {
children: [
new Table({
rows: [ rows: [
new TableRow({ new TableRow({
children: [ children: [
@ -94,10 +96,12 @@ const table = new Table({
], ],
}), }),
], ],
}),
],
},
],
}); });
doc.addSection({ children: [table] });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer); fs.writeFileSync("My Document.docx", buffer);
}); });

View File

@ -10,9 +10,8 @@ const doc = new Document({
creator: "Clippy", creator: "Clippy",
title: "Sample Document", title: "Sample Document",
description: "A brief example of using docx with bookmarks and internal hyperlinks", description: "A brief example of using docx with bookmarks and internal hyperlinks",
}); sections: [
{
doc.addSection({
footers: { footers: {
default: new Footer({ default: new Footer({
children: [ children: [
@ -57,6 +56,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build"; import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph({ new Paragraph({
bidirectional: true, bidirectional: true,
@ -62,6 +62,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,11 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, ImageRun, Packer, Paragraph, TextRun } from "../build";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/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
doc.addSection({ const doc = new Document({
sections: [
{
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -77,6 +77,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
const table = new Table({ {
children: [
new Table({
rows: [ rows: [
new TableRow({ new TableRow({
children: [ children: [
@ -84,10 +86,10 @@ const table = new Table({
], ],
}), }),
], ],
}); }),
],
doc.addSection({ },
children: [table], ],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -4,18 +4,13 @@ import * as fs from "fs";
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build"; import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8"); const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
const doc = new Document({
title: "Title",
externalStyles: styles
});
// Create a table and pass the XML Style // Create a table and pass the XML Style
const table = new Table({ const table = new Table({
style: 'MyCustomTableStyle', style: "MyCustomTableStyle",
width: { width: {
size: 9070, size: 9070,
type: WidthType.DXA type: WidthType.DXA,
}, },
rows: [ rows: [
new TableRow({ new TableRow({
@ -41,8 +36,14 @@ const table = new Table({
], ],
}); });
doc.addSection({ const doc = new Document({
title: "Title",
externalStyles: styles,
sections: [
{
children: [table], children: [table],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph } from "../build"; import { Document, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph("No border!"), new Paragraph("No border!"),
new Paragraph({ new Paragraph({
@ -26,6 +26,8 @@ doc.addSection({
}, },
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -47,9 +47,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "Hello", text: "Hello",
@ -60,6 +59,8 @@ doc.addSection({
heading: HeadingLevel.HEADING_2, heading: HeadingLevel.HEADING_2,
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,6 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build"; import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
// WordprocessingML docs for TableOfContents can be found here:
// http://officeopenxml.com/WPtableOfContents.php
// Let's define the properties for generate a TOC for heading 1-5 and MySpectacularStyle,
// making the entries be hyperlinks for the paragraph
const doc = new File({ const doc = new File({
styles: { styles: {
paragraphStyles: [ paragraphStyles: [
@ -19,15 +24,8 @@ const doc = new File({
}, },
], ],
}, },
}); sections: [
{
// WordprocessingML docs for TableOfContents can be found here:
// http://officeopenxml.com/WPtableOfContents.php
// Let's define the properties for generate a TOC for heading 1-5 and MySpectacularStyle,
// making the entries be hyperlinks for the paragraph
doc.addSection({
children: [ children: [
new TableOfContents("Summary", { new TableOfContents("Summary", {
hyperlink: true, hyperlink: true,
@ -57,6 +55,8 @@ doc.addSection({
pageBreakBefore: true, pageBreakBefore: true,
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -57,9 +57,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "line with contextual spacing", text: "line with contextual spacing",
@ -277,6 +276,8 @@ doc.addSection({
}, },
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -117,9 +117,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "Hey you", text: "Hey you",
@ -248,6 +247,8 @@ doc.addSection({
}, },
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -12,16 +12,21 @@ fs.readFile(filePath, (err, data) => {
} }
importDotx.extract(data).then((templateDocument) => { importDotx.extract(data).then((templateDocument) => {
const doc = new Document(undefined, { const doc = new Document(
template: templateDocument, {
}); sections: [
{
doc.addSection({
properties: { properties: {
titlePage: templateDocument.titlePageIsDefined, titlePage: templateDocument.titlePageIsDefined,
}, },
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
}); },
],
},
{
template: templateDocument,
},
);
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer); fs.writeFileSync("My Document.docx", buffer);

View File

@ -3,9 +3,11 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build"; import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
const table = new Table({ {
children: [
new Table({
rows: [ rows: [
new TableRow({ new TableRow({
children: [ children: [
@ -65,10 +67,10 @@ const table = new Table({
], ],
}), }),
], ],
}); }),
],
doc.addSection({ },
children: [table], ],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -17,8 +17,6 @@ import {
WidthType, WidthType,
} from "../build"; } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -376,8 +374,9 @@ const table8 = new Table({
type: WidthType.PERCENTAGE, type: WidthType.PERCENTAGE,
}, },
}); });
const doc = new Document({
doc.addSection({ sections: [
{
children: [ children: [
table, table,
new Paragraph({ new Paragraph({
@ -401,6 +400,8 @@ doc.addSection({
new Paragraph("Merging columns 5"), new Paragraph("Merging columns 5"),
table8, table8,
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build"; import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -40,6 +40,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -16,8 +16,6 @@ import {
WidthType, WidthType,
} from "../build"; } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -57,8 +55,12 @@ const table = new Table({
layout: TableLayoutType.FIXED, layout: TableLayoutType.FIXED,
}); });
doc.addSection({ const doc = new Document({
sections: [
{
children: [table], children: [table],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -22,9 +22,8 @@ const doc = new Document({
], ],
}, },
}, },
}); sections: [
{
doc.addSection({
footers: { footers: {
default: new Footer({ default: new Footer({
children: [ children: [
@ -96,6 +95,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Header, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import { Document, Header, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -69,13 +67,17 @@ const table = new Table({
}); });
// Adding same table in the body and in the header // Adding same table in the body and in the header
doc.addSection({ const doc = new Document({
sections: [
{
headers: { headers: {
default: new Header({ default: new Header({
children: [table], children: [table],
}), }),
}, },
children: [table], children: [table],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Header, ImageRun, Packer, Paragraph } from "../build"; import { Document, Header, ImageRun, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -46,6 +46,8 @@ doc.addSection({
}), }),
}, },
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -4,9 +4,9 @@ import * as fs from "fs";
// import { Document, Packer, Paragraph } from "../build"; // import { Document, Packer, Paragraph } from "../build";
import { Document, ImageRun, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build"; import { Document, ImageRun, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph( new Paragraph(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.",
@ -17,7 +17,8 @@ doc.addSection({
new Paragraph( new Paragraph(
"Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.", "Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.",
), ),
new Paragraph( new Paragraph({
children: [
new ImageRun({ new ImageRun({
data: fs.readFileSync("./demo/images/pizza.gif"), data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: { transformation: {
@ -41,7 +42,10 @@ doc.addSection({
}, },
}, },
}), }),
), ],
}),
],
},
], ],
}); });

View File

@ -3,9 +3,17 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build"; import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
const doc = new Document({}); const doc = new Document({
sections: [
doc.addSection({ {
properties: {
page: {
pageNumbers: {
start: 1,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -41,10 +49,6 @@ doc.addSection({
], ],
}), }),
}, },
properties: {
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Hello World 1"), new PageBreak()], children: [new TextRun("Hello World 1"), new PageBreak()],
@ -62,6 +66,8 @@ doc.addSection({
children: [new TextRun("Hello World 5"), new PageBreak()], children: [new TextRun("Hello World 5"), new PageBreak()],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build"; import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
columnWidths: [3505, 5505], columnWidths: [3505, 5505],
rows: [ rows: [
@ -114,7 +112,9 @@ const table3 = new Table({
], ],
}); });
doc.addSection({ const doc = new Document({
sections: [
{
children: [ children: [
new Paragraph({ text: "Table with skewed widths" }), new Paragraph({ text: "Table with skewed widths" }),
table, table,
@ -123,6 +123,8 @@ doc.addSection({
new Paragraph({ text: "Table without setting widths" }), new Paragraph({ text: "Table without setting widths" }),
table3, table3,
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,12 +3,14 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build"; import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: { properties: {
lineNumberCountBy: 1, lineNumbers: {
lineNumberRestart: LineNumberRestartFormat.CONTINUOUS, countBy: 1,
restart: LineNumberRestartFormat.CONTINUOUS,
},
}, },
children: [ children: [
new Paragraph({ new Paragraph({
@ -22,6 +24,8 @@ doc.addSection({
"Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.", "Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.",
), ),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -252,8 +250,12 @@ const table2 = new Table({
], ],
}); });
doc.addSection({ const doc = new Document({
sections: [
{
children: [table, new Paragraph(""), table2], children: [table, new Paragraph(""), table2],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "../build"; import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -40,12 +40,15 @@ doc.addSection({
}), }),
new Paragraph("Second Page"), new Paragraph("Second Page"),
], ],
}); },
{
doc.addSection({
properties: { properties: {
pageNumberStart: 1, page: {
pageNumberSeparator: PageNumberSeparator.EM_DASH pageNumbers: {
start: 1,
separator: PageNumberSeparator.EM_DASH,
},
},
}, },
headers: { headers: {
default: new Header({ default: new Header({
@ -81,6 +84,8 @@ doc.addSection({
}), }),
new Paragraph("Fourth Page"), new Paragraph("Fourth Page"),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build"; import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -75,8 +73,12 @@ const table = new Table({
], ],
}); });
doc.addSection({ const doc = new Document({
sections: [
{
children: [table], children: [table],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph } from "../build"; import { Document, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: { properties: {
column: { column: {
space: 708, space: 708,
@ -18,9 +18,8 @@ doc.addSection({
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
), ),
], ],
}); },
{
doc.addSection({
properties: { properties: {
column: { column: {
space: 708, space: 708,
@ -33,9 +32,8 @@ doc.addSection({
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
), ),
], ],
}); },
{
doc.addSection({
properties: { properties: {
column: { column: {
space: 708, space: 708,
@ -49,6 +47,8 @@ doc.addSection({
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
), ),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build"; import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -28,6 +28,8 @@ doc.addSection({
}), }),
}, },
children: [], children: [],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build"; import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -57,6 +57,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build"; import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
const doc = new Document();
const header = new Header({ const header = new Header({
children: [ children: [
new Paragraph({ new Paragraph({
@ -26,40 +24,51 @@ const footer = new Footer({
children: [new Paragraph("Foo Bar corp. ")], children: [new Paragraph("Foo Bar corp. ")],
}); });
doc.addSection({ const doc = new Document({
sections: [
{
properties: {
page: {
pageNumbers: {
start: 1,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: header, default: header,
}, },
footers: { footers: {
default: footer, default: footer,
}, },
properties: {
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Section 1"), new PageBreak(), new TextRun("Section 1"), new PageBreak()], children: [new TextRun("Section 1"), new PageBreak(), new TextRun("Section 1"), new PageBreak()],
}), }),
], ],
}); },
{
doc.addSection({ properties: {
page: {
pageNumbers: {
start: 1,
formatType: PageNumberFormat.DECIMAL,
},
},
},
headers: { headers: {
default: header, default: header,
}, },
footers: { footers: {
default: footer, default: footer,
}, },
properties: {
pageNumberStart: 1,
pageNumberFormatType: PageNumberFormat.DECIMAL,
},
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Section 2"), new PageBreak(), new TextRun("Section 2"), new PageBreak()], children: [new TextRun("Section 2"), new PageBreak(), new TextRun("Section 2"), new PageBreak()],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build"; import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: { properties: {
verticalAlign: SectionVerticalAlignValue.CENTER, verticalAlign: SectionVerticalAlignValue.CENTER,
}, },
@ -24,6 +24,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -15,8 +15,6 @@ import {
VerticalAlign, VerticalAlign,
} from "../build"; } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -160,7 +158,9 @@ const noBorderTable = new Table({
], ],
}); });
doc.addSection({ children: [table, new Paragraph("Hello"), noBorderTable] }); const doc = new Document({
sections: [{ children: [table, new Paragraph("Hello"), noBorderTable] }],
});
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer); fs.writeFileSync("My Document.docx", buffer);

View File

@ -12,9 +12,9 @@ import {
VerticalPositionRelativeFrom, VerticalPositionRelativeFrom,
} from "../build"; } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
children: [ children: [
new Paragraph("Hello World"), new Paragraph("Hello World"),
new Paragraph({ new Paragraph({
@ -127,6 +127,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,8 +3,6 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build"; import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build";
const doc = new Document();
const table = new Table({ const table = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
@ -66,7 +64,9 @@ const table = new Table({
], ],
}); });
doc.addSection({ const doc = new Document({
sections: [
{
children: [ children: [
new Paragraph({ new Paragraph({
text: "Hello World", text: "Hello World",
@ -85,6 +85,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -25,9 +25,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -50,6 +49,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -18,9 +18,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "KFCを食べるのが好き", text: "KFCを食べるのが好き",
@ -30,6 +29,8 @@ doc.addSection({
text: "こんにちは", text: "こんにちは",
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -41,9 +41,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "中文和英文 Chinese and English", text: "中文和英文 Chinese and English",
@ -83,6 +82,8 @@ doc.addSection({
発闘美慎健育旅布容広互無秋認天歌媛芸。転器合読県増認会賞倒点系。食気母服絵知去祝芸車報熱勝。能貿月更障文的欠賞現覇声敏施会。懲病写昼法族業律記聡生開緊楽暮護。東地二員者説盟治害討面提。第北乗査庭年近的禁疑報方店記必迷都流通。聞有力前愛院梨野関業前訳本清滋補。蒲読火死勝広保会婚際気二由保国。用君込村需起相点選紙拡氏訃不。`, 発闘美慎健育旅布容広互無秋認天歌媛芸。転器合読県増認会賞倒点系。食気母服絵知去祝芸車報熱勝。能貿月更障文的欠賞現覇声敏施会。懲病写昼法族業律記聡生開緊楽暮護。東地二員者説盟治害討面提。第北乗査庭年近的禁疑報方店記必迷都流通。聞有力前愛院梨野関業前訳本清滋補。蒲読火死勝広保会婚際気二由保国。用君込村需起相点選紙拡氏訃不。`,
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -22,9 +22,9 @@ import {
TextRun, TextRun,
} from "../build"; } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -287,6 +287,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -7,9 +7,8 @@ const doc = new Document({
background: { background: {
color: "C45911", color: "C45911",
}, },
}); sections: [
{
doc.addSection({
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -26,6 +25,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -40,9 +40,8 @@ const doc = new Document({
}, },
], ],
}, },
}); sections: [
{
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "How to make cake", text: "How to make cake",
@ -81,6 +80,8 @@ doc.addSection({
heading: HeadingLevel.HEADING_1, heading: HeadingLevel.HEADING_1,
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun, SectionType } from "../build"; import { Document, Packer, Paragraph, TextRun, SectionType } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -18,9 +18,8 @@ doc.addSection({
], ],
}), }),
], ],
}); },
{
doc.addSection({
properties: { properties: {
type: SectionType.CONTINUOUS, type: SectionType.CONTINUOUS,
}, },
@ -35,9 +34,8 @@ doc.addSection({
], ],
}), }),
], ],
}); },
{
doc.addSection({
properties: { properties: {
type: SectionType.ODD_PAGE, type: SectionType.ODD_PAGE,
}, },
@ -52,9 +50,8 @@ doc.addSection({
], ],
}), }),
], ],
}); },
{
doc.addSection({
properties: { properties: {
type: SectionType.EVEN_PAGE, type: SectionType.EVEN_PAGE,
}, },
@ -69,9 +66,8 @@ doc.addSection({
], ],
}), }),
], ],
}); },
{
doc.addSection({
properties: { properties: {
type: SectionType.NEXT_PAGE, type: SectionType.NEXT_PAGE,
}, },
@ -86,6 +82,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Footer, Header, Packer, Paragraph } from "../build"; import { Document, Footer, Header, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: { properties: {
header: 100, header: 100,
footer: 50, footer: 50,
@ -41,6 +41,8 @@ doc.addSection({
}), }),
}, },
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,15 +3,19 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build"; import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
margins: { properties: {
page: {
margin: {
top: 0, top: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
left: 0, left: 0,
}, },
},
},
children: [ children: [
new Paragraph({ new Paragraph({
children: [ children: [
@ -33,6 +37,8 @@ doc.addSection({
new Paragraph("Foo bar"), new Paragraph("Foo bar"),
new Paragraph("Github is the best"), new Paragraph("Github is the best"),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -26,6 +26,27 @@ import {
Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it. Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it.
*/ */
const paragraph = new Paragraph({
children: [
new TextRun("This is a simple demo "),
new TextRun({
text: "on how to ",
}),
new InsertedTextRun({
text: "mark a text as an insertion ",
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
new DeletedTextRun({
text: "or a deletion.",
id: 1,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
],
});
const doc = new Document({ const doc = new Document({
footnotes: { footnotes: {
1: { 1: {
@ -53,30 +74,8 @@ const doc = new Document({
features: { features: {
trackRevisions: true, trackRevisions: true,
}, },
}); sections: [
{
const paragraph = new Paragraph({
children: [
new TextRun("This is a simple demo "),
new TextRun({
text: "on how to ",
}),
new InsertedTextRun({
text: "mark a text as an insertion ",
id: 0,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
new DeletedTextRun({
text: "or a deletion.",
id: 1,
author: "Firstname Lastname",
date: "2020-10-06T09:00:00Z",
}),
],
});
doc.addSection({
properties: {}, properties: {},
children: [ children: [
paragraph, paragraph,
@ -143,6 +142,8 @@ doc.addSection({
], ],
}), }),
}, },
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, FrameAnchorType, HorizontalPositionAlign, Packer, Paragraph, TextRun, VerticalPositionAlign } from "../build"; import { Document, FrameAnchorType, HorizontalPositionAlign, Packer, Paragraph, TextRun, VerticalPositionAlign } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -64,6 +64,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, LineRuleType, Packer, Paragraph, TextRun } from "../build"; import { Document, LineRuleType, Packer, Paragraph, TextRun } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -27,6 +27,8 @@ doc.addSection({
], ],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -5,9 +5,8 @@ import { Document, Footer, Header, Packer, PageBreak, Paragraph, TextRun } from
const doc = new Document({ const doc = new Document({
evenAndOddHeaderAndFooters: true, evenAndOddHeaderAndFooters: true,
}); sections: [
{
doc.addSection({
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -63,6 +62,8 @@ doc.addSection({
children: [new TextRun("Hello World 5"), new PageBreak()], children: [new TextRun("Hello World 5"), new PageBreak()],
}), }),
], ],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,13 +3,19 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, PageOrientation, Paragraph } from "../build"; import { Document, Packer, PageOrientation, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
properties: {
page: {
size: { size: {
orientation: PageOrientation.LANDSCAPE, orientation: PageOrientation.LANDSCAPE,
}, },
},
},
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Footer, Header, Packer, Paragraph } from "../build"; import { Document, Footer, Header, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [new Paragraph("Header text")], children: [new Paragraph("Header text")],
@ -17,6 +17,8 @@ doc.addSection({
}), }),
}, },
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -3,9 +3,9 @@
import * as fs from "fs"; import * as fs from "fs";
import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "../build"; import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "../build";
const doc = new Document(); const doc = new Document({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header({ default: new Header({
children: [ children: [
@ -41,6 +41,8 @@ doc.addSection({
}), }),
}, },
children: [new Paragraph("Hello World")], children: [new Paragraph("Hello World")],
},
],
}); });
Packer.toBuffer(doc).then((buffer) => { Packer.toBuffer(doc).then((buffer) => {

View File

@ -14,7 +14,9 @@
function generate() { function generate() {
const doc = new docx.Document(); const doc = new docx.Document();
doc.addSection({ const doc = new Document({
sections: [
{
children: [ children: [
new docx.Paragraph({ new docx.Paragraph({
children: [ children: [
@ -30,10 +32,10 @@
], ],
}), }),
], ],
},
],
}); });
docx.Packer.toBlob(doc).then((blob) => { docx.Packer.toBlob(doc).then((blob) => {
console.log(blob); console.log(blob);
saveAs(blob, "example.docx"); saveAs(blob, "example.docx");

View File

@ -24,12 +24,10 @@ import { ... } from "docx";
import * as fs from "fs"; import * as fs from "fs";
import { Document, Packer, Paragraph, TextRun } from "docx"; import { Document, Packer, Paragraph, TextRun } from "docx";
// Create document
const doc = new Document();
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections // Documents contain sections, you can have multiple sections per document, go here to learn more about sections
// This simple example will only contain one section // This simple example will only contain one section
doc.addSection({ const doc = new Document({
sections: [{
properties: {}, properties: {},
children: [ children: [
new Paragraph({ new Paragraph({
@ -46,6 +44,7 @@ doc.addSection({
], ],
}), }),
], ],
}];
}); });
// Used to export the file into a .docx file // Used to export the file into a .docx file

View File

@ -57,12 +57,14 @@ text.contents = "Hello World";
**Do** **Do**
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Hello World")], children: [new TextRun("Hello World")],
}), }),
], ],
}];
}); });
``` ```

View File

@ -6,7 +6,8 @@
To make a bullet point, simply make a paragraph into a bullet point: To make a bullet point, simply make a paragraph into a bullet point:
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [ children: [
new Paragraph({ new Paragraph({
text: "Bullet points", text: "Bullet points",
@ -21,6 +22,7 @@ doc.addSection({
} }
}) })
], ],
}];
}); });
``` ```

View File

@ -5,7 +5,8 @@
Every Section has a sections which you can define its Headers and Footers: Every Section has a sections which you can define its Headers and Footers:
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
headers: { headers: {
default: new Header({ // The standard default header default: new Header({ // The standard default header
children: [], children: [],
@ -29,6 +30,7 @@ doc.addSection({
}), }),
}, },
children: [], children: [],
}];
}); });
``` ```

View File

@ -37,20 +37,14 @@ const image = new ImageRun({
Add it into the document by adding the image into a paragraph: Add it into the document by adding the image into a paragraph:
```ts ```ts
doc.addSection({ const doc = new Document({
children: [new Paragraph(image)], sections: [{
});
```
Or:
```ts
doc.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
children: [image], children: [image],
}), }),
], ],
}];
}); });
``` ```
@ -59,16 +53,22 @@ doc.addSection({
Adding images can be easily done by creating an instance of `ImageRun`. This can be added in a `Paragraph` or `Hyperlink`: Adding images can be easily done by creating an instance of `ImageRun`. This can be added in a `Paragraph` or `Hyperlink`:
```ts ```ts
const image = new ImageRun({ const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [
new ImageRun({
data: [IMAGE_BUFFER], data: [IMAGE_BUFFER],
transformation: { transformation: {
width: [IMAGE_SIZE], width: [IMAGE_SIZE],
height: [IMAGE_SIZE], height: [IMAGE_SIZE],
}, },
}); }),
],
doc.addSection({ }),
children: [new Paragraph(image)], ],
}];
}); });
``` ```

View File

@ -35,20 +35,24 @@ const paragraph = new Paragraph({
After you create the paragraph, you must add the paragraph into a `section`: After you create the paragraph, you must add the paragraph into a `section`:
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [paragraph], children: [paragraph],
}];
}); });
``` ```
Or the preferred convension, define the paragraph inside the section and remove the usage of variables: Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")], children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
}), }),
], ],
}];
}); });
``` ```

View File

@ -11,12 +11,14 @@ For example, you could have one section which is portrait with a header and foot
This creates a simple section in a document with one paragraph inside: This creates a simple section in a document with one paragraph inside:
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [ children: [
new Paragraph({ new Paragraph({
children: [new TextRun("Hello World")], children: [new TextRun("Hello World")],
}), }),
], ],
}];
}); });
``` ```
@ -35,7 +37,8 @@ Setting the section type determines how the contents of the section will be plac
- `ODD_PAGE` - `ODD_PAGE`
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
properties: { properties: {
type: SectionType.CONTINUOUS, type: SectionType.CONTINUOUS,
} }
@ -44,5 +47,6 @@ doc.addSection({
children: [new TextRun("Hello World")], children: [new TextRun("Hello World")],
}), }),
], ],
}];
}); });
``` ```

View File

@ -19,8 +19,10 @@ const table = new Table({
Then add the table in the `section` Then add the table in the `section`
```ts ```ts
doc.addSection({ const doc = new Document({
sections: [{
children: [table], children: [table],
}];
}); });
``` ```

View File

@ -1,38 +1,10 @@
import { expect } from "chai"; import { expect } from "chai";
import { File, HeadingLevel, Media, Paragraph } from "file"; import { Media } from "file";
import { ImageReplacer } from "./image-replacer"; import { ImageReplacer } from "./image-replacer";
describe("ImageReplacer", () => { describe("ImageReplacer", () => {
let file: File;
beforeEach(() => {
file = new File({
creator: "Dolan Miu",
revision: "1",
lastModifiedBy: "Dolan Miu",
});
file.addSection({
children: [
new Paragraph({
text: "title",
heading: HeadingLevel.TITLE,
}),
new Paragraph({
text: "Hello world",
heading: HeadingLevel.HEADING_1,
}),
new Paragraph({
text: "heading 2",
heading: HeadingLevel.HEADING_2,
}),
new Paragraph("test text"),
],
});
});
describe("#replace()", () => { describe("#replace()", () => {
it("should replace properly", () => { it("should replace properly", () => {
const imageReplacer = new ImageReplacer(); const imageReplacer = new ImageReplacer();

View File

@ -8,16 +8,17 @@ import { Compiler } from "./next-compiler";
describe("Compiler", () => { describe("Compiler", () => {
let compiler: Compiler; let compiler: Compiler;
let file: File;
beforeEach(() => { beforeEach(() => {
file = new File();
compiler = new Compiler(); compiler = new Compiler();
}); });
describe("#compile()", () => { describe("#compile()", () => {
it("should pack all the content", async function () { it("should pack all the content", async function () {
this.timeout(99999999); this.timeout(99999999);
const file = new File({
sections: [],
});
const zipFile = compiler.compile(file); const zipFile = compiler.compile(file);
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
@ -38,7 +39,9 @@ describe("Compiler", () => {
}); });
it("should pack all additional headers and footers", async function () { it("should pack all additional headers and footers", async function () {
file.addSection({ const file = new File({
sections: [
{
headers: { headers: {
default: new Header(), default: new Header(),
}, },
@ -46,9 +49,8 @@ describe("Compiler", () => {
default: new Footer(), default: new Footer(),
}, },
children: [], children: [],
}); },
{
file.addSection({
headers: { headers: {
default: new Header(), default: new Header(),
}, },
@ -56,6 +58,8 @@ describe("Compiler", () => {
default: new Footer(), default: new Footer(),
}, },
children: [], children: [],
},
],
}); });
this.timeout(99999999); this.timeout(99999999);
@ -80,12 +84,15 @@ describe("Compiler", () => {
// This test is required because before, there was a case where Document was formatted twice, which was inefficient // This test is required because before, there was a case where Document was formatted twice, which was inefficient
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times. // This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
const paragraph = new Paragraph(""); const paragraph = new Paragraph("");
const doc = new File(); const file = new File({
sections: [
doc.addSection({ {
properties: {}, properties: {},
children: [paragraph], children: [paragraph],
},
],
}); });
// tslint:disable-next-line: no-string-literal // tslint:disable-next-line: no-string-literal
const spy = sinon.spy(compiler["formatter"], "format"); const spy = sinon.spy(compiler["formatter"], "format");

View File

@ -14,9 +14,8 @@ describe("Packer", () => {
creator: "Dolan Miu", creator: "Dolan Miu",
revision: "1", revision: "1",
lastModifiedBy: "Dolan Miu", lastModifiedBy: "Dolan Miu",
}); sections: [
{
file.addSection({
children: [ children: [
new Paragraph({ new Paragraph({
text: "title", text: "title",
@ -32,6 +31,8 @@ describe("Packer", () => {
}), }),
new Paragraph("test text"), new Paragraph("test text"),
], ],
},
],
}); });
}); });

View File

@ -3,12 +3,14 @@ import { ICustomPropertyOptions } from "../custom-properties";
import { IDocumentBackgroundOptions } from "../document"; import { IDocumentBackgroundOptions } from "../document";
import { DocumentAttributes } from "../document/document-attributes"; import { DocumentAttributes } from "../document/document-attributes";
import { ISectionOptions } from "../file";
import { INumberingOptions } from "../numbering"; import { INumberingOptions } from "../numbering";
import { Paragraph } from "../paragraph"; import { Paragraph } from "../paragraph";
import { IStylesOptions } from "../styles"; import { IStylesOptions } from "../styles";
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components"; import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
export interface IPropertiesOptions { export interface IPropertiesOptions {
readonly sections: ISectionOptions[];
readonly title?: string; readonly title?: string;
readonly subject?: string; readonly subject?: string;
readonly creator?: string; readonly creator?: string;
@ -34,7 +36,7 @@ export interface IPropertiesOptions {
} }
export class CoreProperties extends XmlComponent { export class CoreProperties extends XmlComponent {
constructor(options: IPropertiesOptions) { constructor(options: Omit<IPropertiesOptions, "sections">) {
super("cp:coreProperties"); super("cp:coreProperties");
this.root.push( this.root.push(
new DocumentAttributes({ new DocumentAttributes({

View File

@ -14,8 +14,12 @@ describe("Body", () => {
describe("#addSection", () => { describe("#addSection", () => {
it("should add section with default parameters", () => { it("should add section with default parameters", () => {
body.addSection({ body.addSection({
page: {
size: {
width: 10000, width: 10000,
height: 10000, height: 10000,
},
},
}); });
const tree = new Formatter().format(body); const tree = new Formatter().format(body);

View File

@ -1,7 +1,7 @@
import { IContext, IXmlableObject, XmlComponent } from "file/xml-components"; import { IContext, IXmlableObject, XmlComponent } from "file/xml-components";
import { Paragraph, ParagraphProperties, TableOfContents } from "../.."; import { Paragraph, ParagraphProperties, TableOfContents } from "../..";
import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; import { ISectionPropertiesOptions, SectionProperties } from "./section-properties/section-properties";
export class Body extends XmlComponent { export class Body extends XmlComponent {
private readonly sections: SectionProperties[] = []; private readonly sections: SectionProperties[] = [];
@ -18,7 +18,7 @@ export class Body extends XmlComponent {
* - last section should be direct child of body * - last section should be direct child of body
* @param options new section options * @param options new section options
*/ */
public addSection(options: SectionPropertiesOptions): void { public addSection(options: ISectionPropertiesOptions): void {
const currentSection = this.sections.pop() as SectionProperties; const currentSection = this.sections.pop() as SectionProperties;
this.root.push(this.createSectionParagraph(currentSection)); this.root.push(this.createSectionParagraph(currentSection));

View File

@ -8,18 +8,18 @@ export enum LineNumberRestartFormat {
} }
export interface ILineNumberAttributes { export interface ILineNumberAttributes {
readonly lineNumberCountBy?: number; readonly countBy?: number;
readonly lineNumberStart?: number; readonly start?: number;
readonly lineNumberRestart?: LineNumberRestartFormat; readonly restart?: LineNumberRestartFormat;
readonly lineNumberDistance?: number; readonly distance?: number;
} }
export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttributes> { export class LineNumberAttributes extends XmlAttributeComponent<ILineNumberAttributes> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
lineNumberCountBy: "w:countBy", countBy: "w:countBy",
lineNumberStart: "w:start", start: "w:start",
lineNumberRestart: "w:restart", restart: "w:restart",
lineNumberDistance: "w:distance", distance: "w:distance",
}; };
} }
@ -28,10 +28,10 @@ export class LineNumberType extends XmlComponent {
super("w:lnNumType"); super("w:lnNumType");
this.root.push( this.root.push(
new LineNumberAttributes({ new LineNumberAttributes({
lineNumberCountBy: countBy, countBy: countBy,
lineNumberStart: start, start: start,
lineNumberRestart: restart, restart: restart,
lineNumberDistance: dist, distance: dist,
}), }),
); );
} }

View File

@ -26,16 +26,16 @@ export enum PageNumberSeparator {
} }
export interface IPageNumberTypeAttributes { export interface IPageNumberTypeAttributes {
readonly pageNumberStart?: number; readonly start?: number;
readonly pageNumberFormatType?: PageNumberFormat; readonly formatType?: PageNumberFormat;
readonly pageNumberSeparator?: PageNumberSeparator; readonly separator?: PageNumberSeparator;
} }
export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> { export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
pageNumberStart: "w:start", start: "w:start",
pageNumberFormatType: "w:fmt", formatType: "w:fmt",
pageNumberSeparator: "w:chapSep", separator: "w:chapSep",
}; };
} }
@ -44,9 +44,9 @@ export class PageNumberType extends XmlComponent {
super("w:pgNumType"); super("w:pgNumType");
this.root.push( this.root.push(
new PageNumberTypeAttributes({ new PageNumberTypeAttributes({
pageNumberStart: start, start: start,
pageNumberFormatType: numberFormat, formatType: numberFormat,
pageNumberSeparator: separator, separator: separator,
}), }),
); );
} }

View File

@ -19,8 +19,12 @@ describe("SectionProperties", () => {
const media = new Media(); const media = new Media();
const properties = new SectionProperties({ const properties = new SectionProperties({
page: {
size: {
width: 11906, width: 11906,
height: 16838, height: 16838,
},
margin: {
top: convertInchesToTwip(1), top: convertInchesToTwip(1),
right: convertInchesToTwip(1), right: convertInchesToTwip(1),
bottom: convertInchesToTwip(1), bottom: convertInchesToTwip(1),
@ -29,24 +33,32 @@ describe("SectionProperties", () => {
footer: 708, footer: 708,
gutter: 0, gutter: 0,
mirror: false, mirror: false,
},
pageNumbers: {
start: 10,
formatType: PageNumberFormat.CARDINAL_TEXT,
},
},
column: { column: {
space: 708, space: 708,
count: 1, count: 1,
separate: true, separate: true,
}, },
grid: {
linePitch: convertInchesToTwip(0.25), linePitch: convertInchesToTwip(0.25),
headers: { },
headerWrapperGroup: {
default: new HeaderWrapper(media, 100), default: new HeaderWrapper(media, 100),
}, },
footers: { footerWrapperGroup: {
even: new FooterWrapper(media, 200), even: new FooterWrapper(media, 200),
}, },
pageNumberStart: 10,
pageNumberFormatType: PageNumberFormat.CARDINAL_TEXT,
titlePage: true, titlePage: true,
verticalAlign: SectionVerticalAlignValue.TOP, verticalAlign: SectionVerticalAlignValue.TOP,
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
expect(tree["w:sectPr"]).to.be.an.instanceof(Array); expect(tree["w:sectPr"]).to.be.an.instanceof(Array);
expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } }); expect(tree["w:sectPr"][0]).to.deep.equal({ "w:pgSz": { _attr: { "w:h": 16838, "w:w": 11906, "w:orient": "portrait" } } });
@ -98,7 +110,11 @@ describe("SectionProperties", () => {
it("should create section properties with changed options", () => { it("should create section properties with changed options", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
page: {
margin: {
top: 0, top: 0,
},
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
@ -122,7 +138,11 @@ describe("SectionProperties", () => {
it("should create section properties with changed options", () => { it("should create section properties with changed options", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
page: {
margin: {
bottom: 0, bottom: 0,
},
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
@ -146,8 +166,12 @@ describe("SectionProperties", () => {
it("should create section properties with changed options", () => { it("should create section properties with changed options", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
page: {
size: {
width: 0, width: 0,
height: 0, height: 0,
},
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
@ -171,9 +195,13 @@ describe("SectionProperties", () => {
it("should create section properties with page borders", () => { it("should create section properties with page borders", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
page: {
borders: {
pageBorders: { pageBorders: {
offsetFrom: PageBorderOffsetFrom.PAGE, offsetFrom: PageBorderOffsetFrom.PAGE,
}, },
},
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
@ -185,7 +213,11 @@ describe("SectionProperties", () => {
it("should create section properties with page number type, but without start attribute", () => { it("should create section properties with page number type, but without start attribute", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN, page: {
pageNumbers: {
formatType: PageNumberFormat.UPPER_ROMAN,
},
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
@ -217,10 +249,12 @@ describe("SectionProperties", () => {
it("should create section properties line number type", () => { it("should create section properties line number type", () => {
const properties = new SectionProperties({ const properties = new SectionProperties({
lineNumberCountBy: 2, lineNumbers: {
lineNumberStart: 2, countBy: 2,
lineNumberRestart: LineNumberRestartFormat.CONTINUOUS, start: 2,
lineNumberDistance: 4, restart: LineNumberRestartFormat.CONTINUOUS,
distance: 4,
},
}); });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]); expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);

View File

@ -1,4 +1,6 @@
// http://officeopenxml.com/WPsection.php // http://officeopenxml.com/WPsection.php
// tslint:disable: no-unnecessary-initializer
import { convertInchesToTwip } from "convenience-functions"; import { convertInchesToTwip } from "convenience-functions";
import { FooterWrapper } from "file/footer-wrapper"; import { FooterWrapper } from "file/footer-wrapper";
import { HeaderWrapper } from "file/header-wrapper"; import { HeaderWrapper } from "file/header-wrapper";
@ -21,7 +23,7 @@ import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attr
import { TitlePage } from "./title-page/title-page"; import { TitlePage } from "./title-page/title-page";
import { Type } from "./type/section-type"; import { Type } from "./type/section-type";
import { SectionType } from "./type/section-type-attributes"; import { SectionType } from "./type/section-type-attributes";
import { ISectionVerticalAlignAttributes, SectionVerticalAlign } from "./vertical-align"; import { SectionVerticalAlign, SectionVerticalAlignValue } from "./vertical-align";
export interface IHeaderFooterGroup<T> { export interface IHeaderFooterGroup<T> {
readonly default?: T; readonly default?: T;
@ -29,46 +31,31 @@ export interface IHeaderFooterGroup<T> {
readonly even?: T; readonly even?: T;
} }
interface IHeadersOptions { export interface ISectionPropertiesOptions {
readonly headers?: IHeaderFooterGroup<HeaderWrapper>; readonly page?: {
} readonly size?: IPageSizeAttributes;
readonly margin?: IPageMarginAttributes;
interface IFootersOptions { readonly pageNumbers?: IPageNumberTypeAttributes;
readonly footers?: IHeaderFooterGroup<FooterWrapper>; readonly borders?: IPageBordersOptions;
} };
readonly grid?: IDocGridAttributesProperties;
interface ITitlePageOptions { readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>;
readonly lineNumbers?: ILineNumberAttributes;
readonly titlePage?: boolean; readonly titlePage?: boolean;
} readonly verticalAlign?: SectionVerticalAlignValue;
export type SectionPropertiesOptions = IPageSizeAttributes &
IPageMarginAttributes &
IDocGridAttributesProperties &
IHeadersOptions &
IFootersOptions &
IPageNumberTypeAttributes &
ILineNumberAttributes &
IPageBordersOptions &
ITitlePageOptions &
ISectionVerticalAlignAttributes & {
readonly column?: { readonly column?: {
readonly space?: number; readonly space?: number;
readonly count?: number; readonly count?: number;
readonly separate?: boolean; readonly separate?: boolean;
}; };
readonly type?: SectionType; readonly type?: SectionType;
}; }
// Need to decouple this from the attributes
export class SectionProperties extends XmlComponent { export class SectionProperties extends XmlComponent {
public readonly width: number; constructor({
public readonly rightMargin: number; page: {
public readonly leftMargin: number; size: { width = 11906, height = 16838, orientation = PageOrientation.PORTRAIT } = {},
margin: {
constructor(
{
width = 11906,
height = 16838,
top = convertInchesToTwip(1), top = convertInchesToTwip(1),
right = convertInchesToTwip(1), right = convertInchesToTwip(1),
bottom = convertInchesToTwip(1), bottom = convertInchesToTwip(1),
@ -77,41 +64,38 @@ export class SectionProperties extends XmlComponent {
footer = 708, footer = 708,
gutter = 0, gutter = 0,
mirror = false, mirror = false,
column = {}, } = {},
linePitch = 360, pageNumbers: {
orientation = PageOrientation.PORTRAIT, start: pageNumberStart = undefined,
headers, formatType: pageNumberFormatType = undefined,
footers, separator: pageNumberSeparator = undefined,
pageNumberFormatType, } = {},
pageNumberStart, borders: {
pageNumberSeparator, pageBorders = undefined,
lineNumberCountBy, pageBorderTop = undefined,
lineNumberStart, pageBorderRight = undefined,
lineNumberRestart, pageBorderBottom = undefined,
lineNumberDistance, pageBorderLeft = undefined,
pageBorders, } = {},
pageBorderTop, } = {},
pageBorderRight, grid: { linePitch = 360 } = {},
pageBorderBottom, headerWrapperGroup = {},
pageBorderLeft, footerWrapperGroup = {},
lineNumbers: { countBy: lineNumberCountBy, start: lineNumberStart, restart: lineNumberRestart, distance: lineNumberDistance } = {},
titlePage = false, titlePage = false,
verticalAlign, verticalAlign,
column: { space = 708, count = 1, separate = false } = {},
type, type,
}: SectionPropertiesOptions = { column: {} }, }: ISectionPropertiesOptions = {}) {
) {
super("w:sectPr"); super("w:sectPr");
this.leftMargin = left;
this.rightMargin = right;
this.width = width;
this.root.push(new PageSize(width, height, orientation)); this.root.push(new PageSize(width, height, orientation));
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror)); this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror));
this.root.push(new Columns(column.space ? column.space : 708, column.count ? column.count : 1, column.separate ?? false)); this.root.push(new Columns(space, count, separate));
this.root.push(new DocumentGrid(linePitch)); this.root.push(new DocumentGrid(linePitch));
this.addHeaders(headers); this.addHeaders(headerWrapperGroup);
this.addFooters(footers); this.addFooters(footerWrapperGroup);
this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType, pageNumberSeparator)); this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType, pageNumberSeparator));
@ -144,8 +128,7 @@ export class SectionProperties extends XmlComponent {
} }
} }
private addHeaders(headers?: IHeaderFooterGroup<HeaderWrapper>): void { private addHeaders(headers: IHeaderFooterGroup<HeaderWrapper>): void {
if (headers) {
if (headers.default) { if (headers.default) {
this.root.push( this.root.push(
new HeaderReference({ new HeaderReference({
@ -173,10 +156,8 @@ export class SectionProperties extends XmlComponent {
); );
} }
} }
}
private addFooters(footers?: IHeaderFooterGroup<FooterWrapper>): void { private addFooters(footers: IHeaderFooterGroup<FooterWrapper>): void {
if (footers) {
if (footers.default) { if (footers.default) {
this.root.push( this.root.push(
new FooterReference({ new FooterReference({
@ -204,5 +185,4 @@ export class SectionProperties extends XmlComponent {
); );
} }
} }
}
} }

View File

@ -1,11 +1,9 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
import { SectionVerticalAlignValue } from "./vertical-align"; import { SectionVerticalAlignValue } from "./vertical-align";
export interface ISectionVerticalAlignAttributes { export class SectionVerticalAlignAttributes extends XmlAttributeComponent<{
readonly verticalAlign?: SectionVerticalAlignValue; readonly verticalAlign?: SectionVerticalAlignValue;
} }> {
export class SectionVerticalAlignAttributes extends XmlAttributeComponent<ISectionVerticalAlignAttributes> {
protected readonly xmlKeys = { protected readonly xmlKeys = {
verticalAlign: "w:val", verticalAlign: "w:val",
}; };

View File

@ -1,33 +1,17 @@
import { expect } from "chai"; import { expect } from "chai";
import * as sinon from "sinon";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { File } from "./file"; import { File } from "./file";
import { Footer, Header } from "./header"; import { Footer, Header } from "./header";
import { Paragraph } from "./paragraph"; import { Paragraph } from "./paragraph";
import { Table, TableCell, TableRow } from "./table";
import { TableOfContents } from "./table-of-contents";
describe("File", () => { describe("File", () => {
describe("#constructor", () => { describe("#constructor", () => {
it("should create with correct headers and footers by default", () => {
const doc = new File();
doc.addSection({
children: [],
});
const tree = new Formatter().format(doc.Document.View.Body);
expect(tree["w:body"][0]["w:sectPr"][4]["w:headerReference"]._attr["w:type"]).to.equal("default");
expect(tree["w:body"][0]["w:sectPr"][5]["w:footerReference"]._attr["w:type"]).to.equal("default");
});
it("should create with correct headers and footers", () => { it("should create with correct headers and footers", () => {
const doc = new File(); const doc = new File({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header(), default: new Header(),
}, },
@ -35,6 +19,8 @@ describe("File", () => {
default: new Footer(), default: new Footer(),
}, },
children: [], children: [],
},
],
}); });
const tree = new Formatter().format(doc.Document.View.Body); const tree = new Formatter().format(doc.Document.View.Body);
@ -44,9 +30,9 @@ describe("File", () => {
}); });
it("should create with first headers and footers", () => { it("should create with first headers and footers", () => {
const doc = new File(); const doc = new File({
sections: [
doc.addSection({ {
headers: { headers: {
first: new Header(), first: new Header(),
}, },
@ -54,6 +40,8 @@ describe("File", () => {
first: new Footer(), first: new Footer(),
}, },
children: [], children: [],
},
],
}); });
const tree = new Formatter().format(doc.Document.View.Body); const tree = new Formatter().format(doc.Document.View.Body);
@ -62,9 +50,9 @@ describe("File", () => {
}); });
it("should create with correct headers", () => { it("should create with correct headers", () => {
const doc = new File(); const doc = new File({
sections: [
doc.addSection({ {
headers: { headers: {
default: new Header(), default: new Header(),
first: new Header(), first: new Header(),
@ -76,6 +64,8 @@ describe("File", () => {
even: new Footer(), even: new Footer(),
}, },
children: [], children: [],
},
],
}); });
const tree = new Formatter().format(doc.Document.View.Body); const tree = new Formatter().format(doc.Document.View.Body);
@ -90,11 +80,13 @@ describe("File", () => {
}); });
it("should add child", () => { it("should add child", () => {
const doc = new File(undefined, undefined, [ const doc = new File({
sections: [
{ {
children: [new Paragraph("test")], children: [new Paragraph("test")],
}, },
]); ],
});
const tree = new Formatter().format(doc.Document.View.Body); const tree = new Formatter().format(doc.Document.View.Body);
@ -171,69 +163,13 @@ describe("File", () => {
}); });
}); });
describe("#addSection", () => {
it("should call the underlying document's add a Paragraph", () => {
const file = new File();
const spy = sinon.spy(file.Document.View, "add");
file.addSection({
children: [new Paragraph({})],
});
expect(spy.called).to.equal(true);
});
it("should call the underlying document's add when adding a Table", () => {
const file = new File();
const spy = sinon.spy(file.Document.View, "add");
file.addSection({
children: [
new Table({
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("hello")],
}),
],
}),
],
}),
],
});
expect(spy.called).to.equal(true);
});
it("should call the underlying document's add when adding an Image (paragraph)", () => {
const file = new File();
const spy = sinon.spy(file.Document.View, "add");
// tslint:disable-next-line:no-any
file.addSection({
children: [new Paragraph("")],
});
expect(spy.called).to.equal(true);
});
});
describe("#addSection", () => {
it("should call the underlying document's add", () => {
const file = new File();
const spy = sinon.spy(file.Document.View, "add");
file.addSection({
children: [new TableOfContents()],
});
expect(spy.called).to.equal(true);
});
});
describe("#addTrackRevisionsFeature", () => { describe("#addTrackRevisionsFeature", () => {
it("should call the underlying document's add", () => { it("should call the underlying document's add", () => {
const file = new File({ const file = new File({
features: { features: {
trackRevisions: true, trackRevisions: true,
}, },
sections: [],
}); });
// tslint:disable-next-line: no-unused-expression no-string-literal // tslint:disable-next-line: no-unused-expression no-string-literal
@ -249,6 +185,7 @@ describe("File", () => {
children: [new Paragraph("hello")], children: [new Paragraph("hello")],
}, },
}, },
sections: [],
}); });
const tree = new Formatter().format(wrapper.FootNotes.View); const tree = new Formatter().format(wrapper.FootNotes.View);
@ -435,6 +372,7 @@ describe("File", () => {
styles: { styles: {
default: {}, default: {},
}, },
sections: [],
}); });
const tree = new Formatter().format(doc.Styles); const tree = new Formatter().format(doc.Styles);
@ -454,6 +392,7 @@ describe("File", () => {
it("should create with even and odd headers and footers", () => { it("should create with even and odd headers and footers", () => {
const doc = new File({ const doc = new File({
evenAndOddHeaderAndFooters: true, evenAndOddHeaderAndFooters: true,
sections: [],
}); });
const tree = new Formatter().format(doc.Settings); const tree = new Formatter().format(doc.Settings);

View File

@ -3,13 +3,7 @@ import { ContentTypes } from "./content-types/content-types";
import { CoreProperties, IPropertiesOptions } from "./core-properties"; import { CoreProperties, IPropertiesOptions } from "./core-properties";
import { CustomProperties } from "./custom-properties"; import { CustomProperties } from "./custom-properties";
import { DocumentWrapper } from "./document-wrapper"; import { DocumentWrapper } from "./document-wrapper";
import { import { FooterReferenceType, HeaderReferenceType, ISectionPropertiesOptions } from "./document/body/section-properties";
FooterReferenceType,
HeaderReferenceType,
IPageSizeAttributes,
SectionPropertiesOptions,
} from "./document/body/section-properties";
import { IPageMarginAttributes } from "./document/body/section-properties/page-margin/page-margin-attributes";
import { IFileProperties } from "./file-properties"; import { IFileProperties } from "./file-properties";
import { FooterWrapper, IDocumentFooter } from "./footer-wrapper"; import { FooterWrapper, IDocumentFooter } from "./footer-wrapper";
import { FootnotesWrapper } from "./footnotes-wrapper"; import { FootnotesWrapper } from "./footnotes-wrapper";
@ -37,9 +31,7 @@ export interface ISectionOptions {
readonly first?: Footer; readonly first?: Footer;
readonly even?: Footer; readonly even?: Footer;
}; };
readonly size?: IPageSizeAttributes; readonly properties?: ISectionPropertiesOptions;
readonly margins?: IPageMarginAttributes;
readonly properties?: SectionPropertiesOptions;
readonly children: (Paragraph | Table | TableOfContents)[]; readonly children: (Paragraph | Table | TableOfContents)[];
} }
@ -61,16 +53,14 @@ export class File {
private readonly appProperties: AppProperties; private readonly appProperties: AppProperties;
private readonly styles: Styles; private readonly styles: Styles;
constructor( constructor(options: IPropertiesOptions, fileProperties: IFileProperties = {}) {
options: IPropertiesOptions = { this.coreProperties = new CoreProperties({
creator: "Un-named", ...options,
revision: "1", creator: options.creator ?? "Un-named",
lastModifiedBy: "Un-named", revision: options.revision ?? "1",
}, lastModifiedBy: options.lastModifiedBy ?? "Un-named",
fileProperties: IFileProperties = {}, });
sections: ISectionOptions[] = [],
) {
this.coreProperties = new CoreProperties(options);
this.numbering = new Numbering( this.numbering = new Numbering(
options.numbering options.numbering
? options.numbering ? options.numbering
@ -78,6 +68,7 @@ export class File {
config: [], config: [],
}, },
); );
this.fileRelationships = new Relationships(); this.fileRelationships = new Relationships();
this.customProperties = new CustomProperties(options.customProperties ?? []); this.customProperties = new CustomProperties(options.customProperties ?? []);
this.appProperties = new AppProperties(); this.appProperties = new AppProperties();
@ -131,12 +122,8 @@ export class File {
} }
} }
for (const section of sections) { for (const section of options.sections) {
this.documentWrapper.View.Body.addSection(section.properties ? section.properties : {}); this.addSection(section);
for (const child of section.children) {
this.documentWrapper.View.add(child);
}
} }
if (options.footnotes) { if (options.footnotes) {
@ -153,28 +140,25 @@ export class File {
} }
} }
public addSection({ public verifyUpdateFields(): void {
headers = { default: new Header() }, if (this.documentWrapper.View.getTablesOfContents().length) {
footers = { default: new Header() }, this.settings.addUpdateFields();
margins = {}, }
size = {}, }
properties,
children, private addSection({ headers = {}, footers = {}, children, properties }: ISectionOptions): void {
}: ISectionOptions): void {
this.documentWrapper.View.Body.addSection({ this.documentWrapper.View.Body.addSection({
...properties, ...properties,
headers: { headerWrapperGroup: {
default: headers.default ? this.createHeader(headers.default) : undefined, default: headers.default ? this.createHeader(headers.default) : undefined,
first: headers.first ? this.createHeader(headers.first) : undefined, first: headers.first ? this.createHeader(headers.first) : undefined,
even: headers.even ? this.createHeader(headers.even) : undefined, even: headers.even ? this.createHeader(headers.even) : undefined,
}, },
footers: { footerWrapperGroup: {
default: footers.default ? this.createFooter(footers.default) : undefined, default: footers.default ? this.createFooter(footers.default) : undefined,
first: footers.first ? this.createFooter(footers.first) : undefined, first: footers.first ? this.createFooter(footers.first) : undefined,
even: footers.even ? this.createFooter(footers.even) : undefined, even: footers.even ? this.createFooter(footers.even) : undefined,
}, },
...margins,
...size,
}); });
for (const child of children) { for (const child of children) {
@ -182,12 +166,6 @@ export class File {
} }
} }
public verifyUpdateFields(): void {
if (this.documentWrapper.View.getTablesOfContents().length) {
this.settings.addUpdateFields();
}
}
private createHeader(header: Header): HeaderWrapper { private createHeader(header: Header): HeaderWrapper {
const wrapper = new HeaderWrapper(this.media, this.currentRelationshipId++); const wrapper = new HeaderWrapper(this.media, this.currentRelationshipId++);

View File

@ -6,7 +6,11 @@ describe("Index", () => {
describe("Document", () => { describe("Document", () => {
it("should instantiate the Document", () => { it("should instantiate the Document", () => {
// tslint:disable-next-line: no-unused-expression // tslint:disable-next-line: no-unused-expression
expect(new Document()).to.be.ok; expect(
new Document({
sections: [],
}),
).to.be.ok;
}); });
}); });
}); });