Remove create table helper function

This commit is contained in:
Dolan
2019-06-25 01:21:28 +01:00
parent dfe986331d
commit c97d15cb9f
22 changed files with 132 additions and 422 deletions

View File

@ -1,15 +1,17 @@
// Example of how you would merge cells together
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, HeadingLevel, Packer, Paragraph, ShadingType, WidthType } from "../build";
import { Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, WidthType } from "../build";
const doc = new Document();
let table = doc.createTable({
let table = new Table({
rows: 2,
columns: 2,
});
doc.addTable(table);
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);
@ -20,13 +22,16 @@ doc.addParagraph(
}),
);
table = doc.createTable({
table = new Table({
rows: 2,
columns: 3,
width: 100,
widthUnitType: WidthType.AUTO,
columnWidths: [1000, 1000, 1000],
});
doc.addTable(table);
table
.getCell(0, 0)
.addParagraph(new Paragraph("World"))
@ -45,7 +50,7 @@ doc.addParagraph(
}),
);
table = doc.createTable({
table = new Table({
rows: 2,
columns: 4,
width: 7000,
@ -57,6 +62,9 @@ table = doc.createTable({
left: 400,
},
});
doc.addTable(table);
table.getCell(0, 0).addParagraph(new Paragraph("Foo"));
table.getCell(0, 1).addParagraph(new Paragraph("v"));
@ -97,13 +105,15 @@ table.getRow(0).mergeCells(0, 3);
doc.addParagraph(new Paragraph("hi"));
doc.createTable({
table = new Table({
rows: 2,
columns: 2,
width: 100,
widthUnitType: WidthType.PERCENTAGE,
});
doc.addTable(table);
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {