Files
docx-js/demo/20-table-cell-borders.ts

108 lines
4.4 KiB
TypeScript
Raw Normal View History

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-09-13 00:51:20 +01:00
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
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,
color: "FF0000",
2021-03-19 20:53:56 +00:00
},
bottom: {
style: BorderStyle.DOUBLE,
size: 3,
color: "0000FF",
2021-03-19 20:53:56 +00:00
},
left: {
style: BorderStyle.DASH_DOT_STROKED,
size: 3,
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);
});