Add Convenience functions

This commit is contained in:
Dolan
2020-12-24 03:37:43 +00:00
parent ef12ada5d7
commit 502db14bba
15 changed files with 115 additions and 49 deletions

View File

@ -3,6 +3,7 @@
import * as fs from "fs";
import {
AlignmentType,
convertInchesToTwip,
Document,
Footer,
HeadingLevel,
@ -110,7 +111,7 @@ const doc = new Document({
},
paragraph: {
spacing: { line: 276 },
indent: { left: 720 },
indent: { left: convertInchesToTwip(0.5) },
},
},
{

View File

@ -1,7 +1,7 @@
// Example on how to customise the look at feel using Styles
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
const doc = new Document({
creator: "Clippy",
@ -56,7 +56,7 @@ const doc = new Document({
},
paragraph: {
indent: {
left: 720,
left: convertInchesToTwip(0.5),
},
spacing: {
line: 276,
@ -168,8 +168,7 @@ doc.addSection({
text: "Strong Style",
}),
new TextRun({
text:
" - Very strong.",
text: " - Very strong.",
}),
],
}),

View File

@ -1,7 +1,7 @@
// Custom styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
const doc = new Document({
styles: {
@ -17,7 +17,7 @@ const doc = new Document({
},
paragraph: {
indent: {
left: 720,
left: convertInchesToTwip(0.5),
},
spacing: {
line: 276,

View File

@ -1,7 +1,7 @@
// Numbered lists
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, Document, Packer, Paragraph } from "../build";
import { AlignmentType, convertInchesToTwip, Document, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
@ -15,7 +15,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 720, hanging: 260 },
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
},
},
},
@ -31,7 +31,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 720, hanging: 260 },
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
},
},
},

View File

@ -1,7 +1,7 @@
// Numbering and bullet points example
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, Document, Packer, Paragraph } from "../build";
import { AlignmentType, convertInchesToTwip, Document, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
@ -16,7 +16,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 720, hanging: 260 },
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
},
},
},
@ -27,7 +27,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 1440, hanging: 980 },
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
},
},
},
@ -38,7 +38,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 2160, hanging: 1700 },
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
},
},
},

View File

@ -2,7 +2,20 @@
// Also includes an example on how to center tables
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build";
import {
AlignmentType,
BorderStyle,
convertInchesToTwip,
Document,
HeadingLevel,
Packer,
Paragraph,
ShadingType,
Table,
TableCell,
TableRow,
WidthType,
} from "../build";
const doc = new Document();
@ -37,10 +50,10 @@ const table2 = new Table({
new TableCell({
children: [new Paragraph("World")],
margins: {
top: 1000,
bottom: 1000,
left: 1000,
right: 1000,
top: convertInchesToTwip(0.69),
bottom: convertInchesToTwip(0.69),
left: convertInchesToTwip(0.69),
right: convertInchesToTwip(0.69),
},
columnSpan: 3,
}),
@ -64,7 +77,7 @@ const table2 = new Table({
size: 100,
type: WidthType.AUTO,
},
columnWidths: [1000, 1000, 1000],
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
});
const table3 = new Table({
@ -119,14 +132,14 @@ const table3 = new Table({
}),
],
width: {
size: 7000,
size: convertInchesToTwip(4.86),
type: WidthType.DXA,
},
margins: {
top: 400,
bottom: 400,
right: 400,
left: 400,
top: convertInchesToTwip(0.27),
bottom: convertInchesToTwip(0.27),
right: convertInchesToTwip(0.27),
left: convertInchesToTwip(0.27),
},
});
@ -355,9 +368,7 @@ const table8 = new Table({
],
}),
new TableRow({
children: [
new TableCell({ children: [new Paragraph("4,1")] }),
],
children: [new TableCell({ children: [new Paragraph("4,1")] })],
}),
],
width: {

View File

@ -1,7 +1,7 @@
// Numbered lists - Add parent number in sub number
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph } from "../build";
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, Packer, Paragraph } from "../build";
const doc = new Document({
numbering: {
@ -15,7 +15,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 720, hanging: 260 },
indent: { left: convertInchesToTwip(0.5), hanging: 260 },
},
},
},
@ -26,7 +26,7 @@ const doc = new Document({
alignment: AlignmentType.START,
style: {
paragraph: {
indent: { left: 1.25 * 720, hanging: 1.25 * 260 },
indent: { left: 1.25 * convertInchesToTwip(0.5), hanging: 1.25 * 260 },
},
run: {
bold: true,