deno.land / x / docx@8.5.0 / demo / 2-declaritive-styles.ts

2-declaritive-styles.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Example on how to customize the look at feel using Styles
import * as fs from "fs";import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph, TextRun, UnderlineType } from "docx";
const doc = new Document({ creator: "Clippy", title: "Sample Document", description: "A brief example of using docx", styles: { default: { heading1: { run: { size: 28, bold: true, italics: true, color: "FF0000", }, paragraph: { spacing: { after: 120, }, }, }, heading2: { run: { size: 26, bold: true, underline: { type: UnderlineType.DOUBLE, color: "FF0000", }, }, paragraph: { spacing: { before: 240, after: 120, }, }, }, listParagraph: { run: { color: "#FF0000", }, }, document: { run: { size: "11pt", font: "Calibri", }, paragraph: { alignment: AlignmentType.RIGHT, }, }, }, paragraphStyles: [ { id: "aside", name: "Aside", basedOn: "Normal", next: "Normal", run: { color: "999999", italics: true, }, paragraph: { indent: { left: convertInchesToTwip(0.5), }, spacing: { line: 276, }, }, }, { id: "wellSpaced", name: "Well Spaced", basedOn: "Normal", quickFormat: true, paragraph: { spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 }, }, }, { id: "strikeUnderline", name: "Strike Underline", basedOn: "Normal", quickFormat: true, run: { strike: true, underline: { type: UnderlineType.SINGLE, }, }, }, ], characterStyles: [ { id: "strikeUnderlineCharacter", name: "Strike Underline", basedOn: "Normal", quickFormat: true, run: { strike: true, underline: { type: UnderlineType.SINGLE, }, }, }, ], }, numbering: { config: [ { reference: "my-crazy-numbering", levels: [ { level: 0, format: LevelFormat.LOWER_LETTER, text: "%1)", alignment: AlignmentType.LEFT, }, ], }, ], }, sections: [ { children: [ new Paragraph({ text: "Test heading1, bold and italicized", heading: HeadingLevel.HEADING_1, }), new Paragraph("Some simple content"), new Paragraph({ text: "Test heading2 with double red underline", heading: HeadingLevel.HEADING_2, }), new Paragraph({ text: "Option1", numbering: { reference: "my-crazy-numbering", level: 0, }, style: "aside", }), new Paragraph({ text: "Option5 -- override 2 to 5", numbering: { reference: "my-crazy-numbering", level: 0, }, }), new Paragraph({ text: "Option3", numbering: { reference: "my-crazy-numbering", level: 0, }, }), new Paragraph({ children: [ new TextRun({ text: "Some monospaced content", font: { name: "Monospace", }, }), ], }), new Paragraph({ text: "An aside, in light gray italics and indented", style: "aside", }), new Paragraph({ text: "This is normal, but well-spaced text", style: "wellSpaced", }), new Paragraph({ children: [ new TextRun({ text: "This is a bold run,", bold: true, }), new TextRun(" switching to normal "), new TextRun({ text: "and then underlined ", underline: {}, }), new TextRun({ text: "and then emphasis-mark ", emphasisMark: {}, }), new TextRun({ text: "and back to normal.", }), new TextRun({ text: "This text will be invisible!", vanish: true, }), new TextRun({ text: "This text will be VERY invisible! Word processors cannot override this!", specVanish: true, }), ], }), new Paragraph({ style: "Strong", children: [ new TextRun({ text: "Strong Style", }), new TextRun({ text: " - Very strong.", }), ], }), new Paragraph({ style: "strikeUnderline", children: [ new TextRun({ text: "Underline and Strike", }), new TextRun({ text: " Override Underline ", underline: { type: UnderlineType.NONE, }, }), new TextRun({ text: "Strike and Underline", }), ], }), new Paragraph({ children: [ new TextRun({ text: "Hello World ", }), new TextRun({ style: "strikeUnderlineCharacter", text: "Underline and Strike", }), new TextRun({ text: " Another Hello World", }), new TextRun({ scale: 50, text: " Scaled text", }), ], }), new Paragraph({ scale: 200, children: [ new TextRun({ text: "Scaled paragraph", }), ], }), ], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
docx

Version Info

Tagged at
4 months ago