2018-10-23 09:08:43 -02:00
|
|
|
// Example of how you would create a table with float positions
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2019-02-26 22:20:20 +00:00
|
|
|
import { Document, Packer, Paragraph, RelativeHorizontalPosition, RelativeVerticalPosition, TableAnchorType, WidthType } from "../build";
|
2018-10-23 09:08:43 -02:00
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
2018-10-23 20:03:29 +01:00
|
|
|
const table = doc.createTable(2, 2).float({
|
2018-10-23 09:08:43 -02:00
|
|
|
horizontalAnchor: TableAnchorType.MARGIN,
|
|
|
|
verticalAnchor: TableAnchorType.MARGIN,
|
|
|
|
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
|
2018-10-23 20:03:29 +01:00
|
|
|
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
|
|
|
|
});
|
2018-10-23 09:08:43 -02:00
|
|
|
table.setFixedWidthLayout();
|
2018-11-15 03:00:26 +00:00
|
|
|
table.setWidth(4535, WidthType.DXA);
|
2018-10-23 09:08:43 -02:00
|
|
|
|
2018-12-29 01:57:20 +00:00
|
|
|
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
|
2018-10-23 09:08:43 -02:00
|
|
|
table.getRow(0).mergeCells(0, 1);
|
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|