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

69 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2018-10-23 09:08:43 -02:00
// Example of how you would create a table with float positions
2023-06-05 00:33:43 +01:00
2018-10-23 09:08:43 -02:00
import * as fs from "fs";
2019-06-25 01:21:28 +01:00
import {
Document,
2019-11-24 03:22:50 +00:00
OverlapType,
2019-06-25 01:21:28 +01:00
Packer,
Paragraph,
RelativeHorizontalPosition,
RelativeVerticalPosition,
Table,
TableAnchorType,
2019-09-13 00:51:20 +01:00
TableCell,
2019-06-25 20:57:46 +01:00
TableLayoutType,
2019-09-13 00:51:20 +01:00
TableRow,
2019-06-25 01:21:28 +01:00
WidthType,
2023-06-05 00:33:43 +01:00
} from "docx";
2018-10-23 09:08:43 -02:00
2019-06-25 01:21:28 +01:00
const table = new Table({
2019-09-13 00:51:20 +01:00
rows: [
new TableRow({
children: [
new TableCell({
children: [new Paragraph("Hello")],
columnSpan: 2,
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
],
}),
],
2019-03-18 23:50:21 +00:00
float: {
horizontalAnchor: TableAnchorType.MARGIN,
verticalAnchor: TableAnchorType.MARGIN,
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
2019-11-24 03:22:50 +00:00
overlap: OverlapType.NEVER,
2021-03-16 03:21:05 +00:00
leftFromText: 1000,
rightFromText: 2000,
topFromText: 1500,
bottomFromText: 30,
2019-03-18 23:50:21 +00:00
},
2019-09-29 04:38:07 +01:00
width: {
size: 4535,
type: 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
2021-03-19 20:53:56 +00:00
const doc = new Document({
sections: [
{
children: [table],
},
],
2019-07-31 08:48:02 +01:00
});
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);
});