2018-08-21 02:46:21 +01:00
|
|
|
// Add custom borders to table cell
|
2023-06-05 00:33:43 +01:00
|
|
|
|
2018-08-21 02:46:21 +01:00
|
|
|
import * as fs from "fs";
|
2023-06-05 00:33:43 +01:00
|
|
|
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "docx";
|
2018-08-21 02:46:21 +01:00
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [
|
|
|
|
{
|
2019-09-13 00:51:20 +01:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Table({
|
|
|
|
rows: [
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("Hello")],
|
|
|
|
borders: {
|
|
|
|
top: {
|
|
|
|
style: BorderStyle.DASH_DOT_STROKED,
|
|
|
|
size: 3,
|
2021-05-24 08:42:34 +03:00
|
|
|
color: "FF0000",
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
bottom: {
|
|
|
|
style: BorderStyle.DOUBLE,
|
|
|
|
size: 3,
|
2021-05-24 08:42:34 +03:00
|
|
|
color: "0000FF",
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
left: {
|
|
|
|
style: BorderStyle.DASH_DOT_STROKED,
|
|
|
|
size: 3,
|
2021-05-24 08:42:34 +03:00
|
|
|
color: "00FF00",
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
right: {
|
|
|
|
style: BorderStyle.DASH_DOT_STROKED,
|
|
|
|
size: 3,
|
|
|
|
color: "#ff8000",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
2019-09-13 00:51:20 +01:00
|
|
|
}),
|
|
|
|
],
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-09-13 00:51:20 +01:00
|
|
|
],
|
2019-03-18 23:50:21 +00:00
|
|
|
});
|
2019-06-25 01:21:28 +01:00
|
|
|
|
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);
|
|
|
|
});
|