2018-08-21 02:46:21 +01:00
|
|
|
// Add custom borders to table cell
|
|
|
|
// 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 { BorderStyle, Document, Packer, Paragraph, Table } from "../build";
|
2018-08-21 02:46:21 +01: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: 4,
|
|
|
|
columns: 4,
|
|
|
|
});
|
2019-06-25 01:21:28 +01:00
|
|
|
|
2019-07-31 08:48:02 +01:00
|
|
|
doc.addSection({ children: [table] });
|
2018-08-21 02:46:21 +01:00
|
|
|
table
|
|
|
|
.getCell(2, 2)
|
2019-06-25 23:17:56 +01:00
|
|
|
.add(new Paragraph("Hello"))
|
2018-12-31 01:55:15 +00:00
|
|
|
.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
|
2018-08-21 02:46:21 +01:00
|
|
|
.addBottomBorder(BorderStyle.DOUBLE, 3, "blue")
|
|
|
|
.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green")
|
|
|
|
.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2018-08-21 02:46:21 +01:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|