Files
docx-js/demo/34-floating-tables.ts

42 lines
1012 B
TypeScript
Raw Normal View History

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-06-25 01:21:28 +01:00
import {
Document,
Packer,
Paragraph,
RelativeHorizontalPosition,
RelativeVerticalPosition,
Table,
TableAnchorType,
2019-06-25 20:57:46 +01:00
TableLayoutType,
2019-06-25 01:21:28 +01:00
WidthType,
} from "../build";
2018-10-23 09:08:43 -02:00
const doc = new Document();
2019-06-25 01:21:28 +01:00
const table = new Table({
2019-03-18 23:50:21 +00:00
rows: 2,
columns: 2,
float: {
horizontalAnchor: TableAnchorType.MARGIN,
verticalAnchor: TableAnchorType.MARGIN,
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
},
width: 4535,
widthUnitType: WidthType.DXA,
2019-06-25 20:57:46 +01:00
layout: TableLayoutType.FIXED,
2018-10-23 20:03:29 +01:00
});
2019-06-25 01:21:28 +01:00
2019-06-25 23:17:56 +01:00
table.getCell(0, 0).add(new Paragraph("Hello"));
2018-10-23 09:08:43 -02:00
table.getRow(0).mergeCells(0, 1);
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [table],
});
2019-08-07 22:12:14 +01:00
Packer.toBuffer(doc).then((buffer) => {
2018-10-23 09:08:43 -02:00
fs.writeFileSync("My Document.docx", buffer);
});