Add tests and margain

This commit is contained in:
Dolan
2019-03-18 23:50:21 +00:00
parent 639842332f
commit e67fd9cb2b
19 changed files with 611 additions and 107 deletions

View File

@ -106,7 +106,10 @@ doc.createParagraph("Sir,").style("normalPara");
doc.createParagraph("BRIEF DESCRIPTION").style("normalPara");
const table = new Table(4, 4);
const table = new Table({
rows: 4,
columns: 4,
});
table
.getRow(0)
.getCell(0)

View File

@ -5,7 +5,10 @@ import { BorderStyle, Document, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
const table = doc.createTable({
rows: 4,
columns: 4,
});
table
.getCell(2, 2)
.addParagraph(new Paragraph("Hello"))

View File

@ -5,7 +5,10 @@ import { Document, Media, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
const table = doc.createTable({
rows: 4,
columns: 4,
});
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));

View File

@ -5,7 +5,10 @@ import { Document, Packer, Paragraph, VerticalAlign } from "../build";
const doc = new Document();
const table = doc.createTable(2, 2);
const table = doc.createTable({
rows: 2,
columns: 2,
});
table
.getCell(1, 1)
.addParagraph(new Paragraph("This text should be in the middle of the cell"))

View File

@ -1,33 +1,68 @@
// 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, Packer, Paragraph } from "../build";
import { Document, Packer, Paragraph, WidthType } from "../build";
const doc = new Document();
let table = doc.createTable(2, 2);
let table = doc.createTable({
rows: 2,
columns: 2,
});
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);
doc.createParagraph("Another table").heading2();
table = doc.createTable(2, 3);
table.getCell(0, 0).addParagraph(new Paragraph("World"));
table = doc.createTable({
rows: 2,
columns: 3,
width: 100,
widthUnitType: WidthType.AUTO,
columnWidths: [1000, 1000, 1000],
});
table.getCell(0, 0).addParagraph(new Paragraph("World")).setMargains({
top: 1000,
bottom: 1000,
left: 1000,
right: 1000,
});
table.getRow(0).mergeCells(0, 2);
doc.createParagraph("Another table").heading2();
table = doc.createTable(2, 4);
table = doc.createTable({
rows: 2,
columns: 4,
width: 7000,
widthUnitType: WidthType.DXA,
margains: {
top: 400,
bottom: 400,
right: 400,
left: 400,
},
});
table.getCell(0, 0).addParagraph(new Paragraph("Foo"));
table.getCell(0, 1).addParagraph(new Paragraph("v"));
// table.getCell(1, 0).addParagraph(new Paragraph("Bar1"));
table.getCell(1, 0).addParagraph(new Paragraph("Bar1"));
// table.getCell(1, 1).addParagraph(new Paragraph("Bar2"));
// table.getCell(1, 2).addParagraph(new Paragraph("Bar3"));
// table.getCell(1, 3).addParagraph(new Paragraph("Bar4"));
// table.getRow(0).mergeCells(0, 3);
doc.createParagraph("hi");
doc.createTable({
rows: 2,
columns: 2,
width: 100,
widthUnitType: WidthType.PERCENTAGE,
});
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {

View File

@ -5,14 +5,19 @@ import { Document, Packer, Paragraph, RelativeHorizontalPosition, RelativeVertic
const doc = new Document();
const table = doc.createTable(2, 2).float({
horizontalAnchor: TableAnchorType.MARGIN,
verticalAnchor: TableAnchorType.MARGIN,
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
const table = doc.createTable({
rows: 2,
columns: 2,
float: {
horizontalAnchor: TableAnchorType.MARGIN,
verticalAnchor: TableAnchorType.MARGIN,
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
},
width: 4535,
widthUnitType: WidthType.DXA,
});
table.setFixedWidthLayout();
table.setWidth(4535, WidthType.DXA);
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);

View File

@ -6,7 +6,10 @@ import { Document, Media, Packer, Table } from "../build";
const doc = new Document();
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
const table = new Table(2, 2);
const table = new Table({
rows: 2,
columns: 2,
});
table.getCell(1, 1).addParagraph(image.Paragraph);
// doc.createParagraph("Hello World");

View File

@ -5,7 +5,10 @@ import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
const table = doc.createTable({
rows: 4,
columns: 4,
});
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
const packer = new Packer();

View File

@ -5,7 +5,10 @@ import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(13, 6);
const table = doc.createTable({
rows: 13,
columns: 6,
});
let row = 0;
table.getCell(row, 0).addContent(new Paragraph("0,0"));
table.getCell(row, 1).addContent(new Paragraph("0,1"));

View File

@ -5,7 +5,10 @@ import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
const table = doc.createTable({
rows: 4,
columns: 4,
});
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
table.getColumn(3).mergeCells(1, 2);
// table.getCell(3, 2).addParagraph(new Paragraph("Hello"));