deno.land / x / docx@8.5.0 / demo / 49-table-borders.ts

49-table-borders.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Add custom borders and no-borders to the table itself
import * as fs from "fs";import { BorderStyle, Document, HeadingLevel, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, TextDirection, VerticalAlign,} from "docx";
const table = new Table({ rows: [ new TableRow({ children: [ new TableCell({ borders: { top: { style: BorderStyle.DASH_SMALL_GAP, size: 1, color: "ff0000", }, bottom: { style: BorderStyle.DASH_SMALL_GAP, size: 1, color: "ff0000", }, left: { style: BorderStyle.DASH_SMALL_GAP, size: 1, color: "ff0000", }, right: { style: BorderStyle.DASH_SMALL_GAP, size: 1, color: "ff0000", }, }, children: [new Paragraph("Hello")], }), new TableCell({ children: [], }), ], }), new TableRow({ children: [ new TableCell({ children: [], }), new TableCell({ children: [new Paragraph("World")], }), ], }), ],});
// Using the no-border convenience object. It is the same as writing this manually:// const borders = {// top: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// bottom: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// left: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// right: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// insideHorizontal: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// insideVertical: {// style: BorderStyle.NONE,// size: 0,// color: "auto",// },// };const noBorderTable = new Table({ borders: TableBorders.NONE, rows: [ new TableRow({ children: [ new TableCell({ children: [new Paragraph({}), new Paragraph({})], verticalAlign: VerticalAlign.CENTER, }), new TableCell({ children: [new Paragraph({}), new Paragraph({})], verticalAlign: VerticalAlign.CENTER, }), new TableCell({ children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})], textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT, }), new TableCell({ children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})], textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT, }), ], }), new TableRow({ children: [ new TableCell({ children: [ new Paragraph({ text: "Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah", heading: HeadingLevel.HEADING_1, }), ], }), new TableCell({ children: [ new Paragraph({ text: "This text should be in the middle of the cell", }), ], verticalAlign: VerticalAlign.CENTER, }), new TableCell({ children: [ new Paragraph({ text: "Text above should be vertical from bottom to top", }), ], verticalAlign: VerticalAlign.CENTER, }), new TableCell({ children: [ new Paragraph({ text: "Text above should be vertical from top to bottom", }), ], verticalAlign: VerticalAlign.CENTER, }), ], }), ],});
const doc = new Document({ sections: [{ children: [table, new Paragraph("Hello"), noBorderTable] }],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
docx

Version Info

Tagged at
4 months ago