diff --git a/demo/77-side-by-side-tables.ts b/demo/77-side-by-side-tables.ts new file mode 100644 index 0000000000..64b4bfd854 --- /dev/null +++ b/demo/77-side-by-side-tables.ts @@ -0,0 +1,116 @@ +// Exporting the document as a stream +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, WidthType } from "../build"; + +const table1 = new Table({ + columnWidths: [3505, 5505], + rows: [ + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [new Paragraph("Hello")], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [new Paragraph("World")], + }), + ], + }), + ], +}); + +const table2 = new Table({ + columnWidths: [3505, 5505], + rows: [ + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [new Paragraph("Foo")], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + width: { + size: 3505, + type: WidthType.DXA, + }, + children: [], + }), + new TableCell({ + width: { + size: 5505, + type: WidthType.DXA, + }, + children: [new Paragraph("Bar")], + }), + ], + }), + ], +}); + +const noBorderTable = new Table({ + borders: TableBorders.NONE, + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [table1], + }), + new TableCell({ + children: [table2], + }), + ], + }), + ], +}); + +const doc = new Document({ + sections: [ + { + properties: {}, + children: [noBorderTable], + }, + ], +}); + +const stream = Packer.toStream(doc); +stream.pipe(fs.createWriteStream("My Document.docx"));