-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc_ex.js
258 lines (199 loc) · 6.47 KB
/
doc_ex.js
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
var fs = require('fs');
var path = require('path');
var officegen = require('./plugins');
var IMAGEDIR = __dirname + "/images/";
var OUTDIR = __dirname + "/output/";
//------------------------------------------------------------------------------------------------------------
var docx = officegen('docx');
var header = docx.getHeader().createP();
header.addText('asd');
var pObj = docx.createP();
pObj.options.align = 'left'; // Also 'right' or 'jestify'.
pObj.addText('Simple text for showing addText() function'); pObj.addLineBreak();
pObj.addText(' with color', { color: '000088' }); pObj.addLineBreak();
pObj.addText(' and back color.', { color: '00ffff', back: '000088' });
pObj.addLineBreak(); pObj.addLineBreak(); pObj.addLineBreak();
var pObj = docx.createP();
pObj.addText('Bold + underline', { bold: true, underline: true });
var pObj = docx.createP({ align: 'center' });
pObj.addText('Center this text.');
var pObj = docx.createP();
pObj.options.align = 'right';
pObj.addText('Align this text to the right.');
var pObj = docx.createP({ backline: 'yellow' });
pObj.addText('Those two lines are in the same paragraph,');
pObj.addLineBreak();
pObj.addText('but they are separated by a line break.');
var pObj = docx.createP({align:'center'});
pObj.addLineBreak(); pObj.addLineBreak();
pObj.addImage(path.resolve(IMAGEDIR, 'image (1).jpg'), {cx: 300, cy: 200 });
var pObj = docx.createP ();
pObj.addText ( 'Since ',{font_size : 20 ,font_face:'Ravie'} );
pObj.addText ( 'asd', { back: '00ffff', shdType: 'pct12', shdColor: 'ff0000',font_size : 20 ,font_face:'Jokerman' } ); // Use pattern in the background.
pObj.addText ( ' you can do ' ,{font_size : 20 ,font_face:'Script MT'});
pObj.addText ( 'more cool ', { highlight: true ,font_size : 20 ,font_face:'Small Fonts'} ); // Highlight!
pObj.addText ( 'stuff!', { highlight: 'darkGreen' ,font_size : 20 ,font_face:'Lucida Calligraphy'} ); // Different highlight color.
docx.putPageBreak();
var pObj = docx.createP({align:'center'});
pObj.addLineBreak(); pObj.addLineBreak();
pObj.addImage(path.resolve(IMAGEDIR, 'image (2).jpg'), { cx: 500, cy: 500 });
pObj.addLineBreak();
var pObj = docx.createP();
pObj.addText('Fonts face only.', { font_face: 'Arial' });
pObj.addText(' Fonts face and size.', { font_face: 'JOKER', font_size: 25 });
pObj.addLineBreak();
pObj.addText('External link', { link: 'https://www.google.com' });
pObj.addLineBreak();
// Hyperlinks to bookmarks also supported:
pObj.addText('Internal link', { hyperlink: 'myBookmark' });
// ...
// Start somewhere a bookmark:
pObj.startBookmark('myBookmark');
// ...
// You MUST close your bookmark:
pObj.endBookmark();
pObj.addLineBreak(); pObj.addLineBreak();
var pObj = docx.createListOfNumbers();
pObj.addText('Option 1');
var pObj = docx.createListOfNumbers();
pObj.addText('Option 2');
pObj.addLineBreak(); pObj.addLineBreak();
docx.putPageBreak();
var table = [
[{
val: "Sr. No.",
opts: {
cellColWidth: 4261,
b: true,
sz: '35',
shd: {
fill: "red",
themeFill: "text1",
"themeFillTint": "80"
},
fontFamily: "Avenir Book"
}
}, {
val: "Title1",
opts: {
b: true,
sz: '30',
color: "yellow",
align: "center",
shd: {
fill: "92CDDC",
themeFill: "text1",
"themeFillTint": "80"
}
}
}, {
val: "Title2",
opts: {
align: "right",
vAlign: "center",
cellColWidth: 42,
b: true,
sz: '48',
shd: {
fill: "92CDDC",
themeFill: "text1",
"themeFillTint": "80"
}
}
}],
[1, 'text 1@', 'start'],
[2, 'text 2$', ''],
[3, 'text3?', ''],
[4, 'text4!', 'END'],
]
var tableStyle = {
tableColWidth: 4261,
tableSize: 24,
tableColor: "blue",
tableAlign: "left",
tableFontFamily: "Comic Sans MS",
borders: true
}
docx.createTable(table, tableStyle);
var pObj = docx.createP();
pObj.addLineBreak(); pObj.addLineBreak();
pObj.addImage(path.resolve(IMAGEDIR, 'image (3).jpg'), { cx: 600, cy: 500 });
var FILENAME = "test-doc1.docx";
var out = fs.createWriteStream(OUTDIR + FILENAME);
docx.generate(out);
var docx = officegen('docx');
var pObj = docx.createP();
pObj.addText ( 'asd ',{font_size : 20 ,font_face:'Ravie'} );
pObj.addText ( 'Technology ', { back: '00ffff', shdType: 'pct12', shdColor: 'ff0000',font_size : 20 ,font_face:'Jokerman' } ); // Use pattern in the background.
pObj.addText ( ' And ' ,{font_size : 20 ,font_face:'Script MT'});
pObj.addText ( 'Services ', { highlight: true ,font_size : 20 ,font_face:'Small Fonts'} ); // Highlight!
pObj.addText ( 'asd. Ltd. asd', { highlight: 'darkGreen' ,font_size : 20 ,font_face:'Lucida Calligraphy'} ); // Different highlight color.
var pObj = docx.createListOfNumbers();
pObj.addText('Option 1');
var pObj = docx.createListOfNumbers();
pObj.addText('Option 2');
pObj.addLineBreak(); pObj.addLineBreak();
docx.putPageBreak();
var table = [
[{
val: "Sr. No.",
opts: {
cellColWidth: 4261,
b: true,
sz: '35',
shd: {
fill: "red",
themeFill: "text1",
"themeFillTint": "80"
},
fontFamily: "Avenir Book"
}
}, {
val: "Title1",
opts: {
b: true,
sz: '30',
color: "yellow",
align: "center",
shd: {
fill: "92CDDC",
themeFill: "text1",
"themeFillTint": "80"
}
}
}, {
val: "Title2",
opts: {
align: "right",
vAlign: "center",
cellColWidth: 42,
b: true,
sz: '48',
shd: {
fill: "92CDDC",
themeFill: "text1",
"themeFillTint": "80"
}
}
}],
[1, 'text 1@', 'start'],
[2, 'text 2$', ''],
[3, 'text3?', ''],
[4, 'text4!', 'END'],
]
var tableStyle = {
tableColWidth: 4261,
tableSize: 24,
tableColor: "blue",
tableAlign: "left",
tableFontFamily: "Comic Sans MS",
borders: true
}
docx.createTable(table, tableStyle);
var pObj = docx.createP();
pObj.addLineBreak(); pObj.addLineBreak();
pObj.addImage(path.resolve(IMAGEDIR, 'image (3).jpg'), { cx: 600, cy: 500 });
var FILENAME = "test-doc2.docx";
var out = fs.createWriteStream(OUTDIR + FILENAME);
docx.generate(out);
//------------------------------------------------------------------------------------------------------------