Compare commits
1130 Commits
Author | SHA1 | Date | |
---|---|---|---|
accb1d44d0 | |||
b61f798cd9 | |||
be2ec9d4cf | |||
514fbb1c09 | |||
8ce397f61e | |||
3b0dfb8489 | |||
f4933deaf2 | |||
add2273551 | |||
91b00466a0 | |||
d0612e115e | |||
e4a6cbe887 | |||
0386810714 | |||
d4585f60b3 | |||
18f015a959 | |||
10c866bdea | |||
680c938dcf | |||
c3a617fefd | |||
6362b498a6 | |||
2e30ab29be | |||
44568023cd | |||
c57aaa856d | |||
0f4f24c3f3 | |||
2fe7a2e3d3 | |||
20b62f5768 | |||
ab063eee08 | |||
66c7624b40 | |||
bfc302023f | |||
3505912f74 | |||
ec379f2e4d | |||
2d17954104 | |||
01c834b16b | |||
2aeb2c2e88 | |||
be88086434 | |||
28f0cc681d | |||
def29c535b | |||
168e5e6e11 | |||
ce71f19826 | |||
4fd3f3a6b8 | |||
39763d3869 | |||
36f90edc67 | |||
b0cbd6f609 | |||
d23d4a4557 | |||
07c58ee43c | |||
1037e8f1b9 | |||
f0ae8396f7 | |||
1ae5995f9c | |||
751ad9d304 | |||
0bd1514826 | |||
16bfc78d8d | |||
528008406a | |||
9e3010ac6a | |||
7c1fa6f4bf | |||
f58d31cc3d | |||
286c742ece | |||
3edc51d5a0 | |||
05d4c9688e | |||
d4401d1597 | |||
90358e73f6 | |||
a77ca02ea9 | |||
7785f0df02 | |||
0e6ed6e5ea | |||
70e84c8d38 | |||
11c3886659 | |||
6104e5bc35 | |||
c748b9a7fc | |||
714dbc0179 | |||
7f16cfc359 | |||
78757753c8 | |||
8343edcdf1 | |||
1ab9e08eb9 | |||
e1bc7f34c9 | |||
d5b495df5b | |||
d6256d2acb | |||
f1c7e448ae | |||
b600fd9324 | |||
3bf40ecb33 | |||
ffb650daa9 | |||
d2122e7806 | |||
6b6eb1d7a2 | |||
c80d881105 | |||
3c223c69e9 | |||
2420321008 | |||
29d5421cea | |||
71953cf45a | |||
325866d9c3 | |||
457e9c12e3 | |||
ff4a66466a | |||
cc142cc052 | |||
6e0dc69217 | |||
33332bcf66 | |||
b94f9ac25b | |||
0a7be48dcb | |||
3f3397620e | |||
154bc1df95 | |||
715e436c4c | |||
f5a9bcf839 | |||
31d2da86ff | |||
9dad3ca356 | |||
355e01edc6 | |||
c19bf1c404 | |||
970450074d | |||
91e8295648 | |||
3e40ae862b | |||
236cce604f | |||
0388a564b5 | |||
cd77ceba69 | |||
5ae8731abe | |||
7bb90c55d1 | |||
a07d6378e8 | |||
4fb8d277b4 | |||
73186ce920 | |||
d02f98956f | |||
d186d42bb6 | |||
338f7be967 | |||
b63a6e6e16 | |||
7e9884081e | |||
262f6323d0 | |||
811dd61562 | |||
9801879063 | |||
e30836c935 | |||
352511bb55 | |||
8ce057e25c | |||
0775ecb08b | |||
e909ab9886 | |||
e03bb155b9 | |||
91620d61d8 | |||
0fba450c9a | |||
ca604fb004 | |||
9e998d233c | |||
6c0fd3adec | |||
6ad18420e5 | |||
ef95a16f39 | |||
53861ec18d | |||
81b1569ad2 | |||
66a1992da0 | |||
100356c344 | |||
31905a27b1 | |||
08916176a2 | |||
ffb3d63c92 | |||
22005428ba | |||
a70acd6d63 | |||
af9e0b0d3f | |||
a0c2be8af2 | |||
df9d4b4219 | |||
cdf5015920 | |||
fe9b438a51 | |||
59cbf8c9cb | |||
7af8175034 | |||
bf0393b485 | |||
83a8822cf7 | |||
eada41b8a1 | |||
2c03377c47 | |||
484fc4aa2d | |||
2846014db0 | |||
c9d86619de | |||
ce485dbc29 | |||
4e875b4744 | |||
3f6c006716 | |||
f8f5d43b0c | |||
8c0fe00c6f | |||
c37d9ca5b3 | |||
f3dc1f0712 | |||
a4d96bbf6e | |||
90c40178aa | |||
2ee96b419a | |||
773900b620 | |||
ece440340f | |||
5233b4b5e6 | |||
86de252a52 | |||
c206d23480 | |||
5a53a138d9 | |||
5b5deb198e | |||
88a30e5af7 | |||
0b9ffa9a7b | |||
5052bcde4f | |||
d5409678ee | |||
72c39a9eb2 | |||
2ed7a28d1e | |||
7b2ff00c83 | |||
d5b0083d77 | |||
406183d104 | |||
c6d3e60314 | |||
be71037a13 | |||
c8c64b320b | |||
8514e8ad31 | |||
d505281a7e | |||
58575342e0 | |||
60ad6d6ab5 | |||
f9dec1cb3c | |||
ffd998cbf5 | |||
c713e6f371 | |||
3c55f9fc1f | |||
c9a8a99278 | |||
b309d327f0 | |||
58bad10bfe | |||
26ea6c518f | |||
d4594a97a2 | |||
68f951ef79 | |||
12e29c6a75 | |||
05eedb2ac1 | |||
8cbc6c15fe | |||
2c21f64b9f | |||
7ec9cff433 | |||
3f979b9981 | |||
3077ca96a7 | |||
46ded68369 | |||
b3a53d341d | |||
afcd5e70a1 | |||
ae48999e38 | |||
4c38e45455 | |||
ec847dccf9 | |||
ca47a1dc3f | |||
cc53ff417b | |||
fcba817a4a | |||
bcd8249d17 | |||
bc0a197ba1 | |||
2e16279d7b | |||
87590aedbd | |||
0fef7763d5 | |||
e55698d221 | |||
d410b5e96f | |||
8587601411 | |||
5b67cb21c6 | |||
42fd9d06de | |||
1e0b74fd27 | |||
21934ec85b | |||
b4f01fb6ec | |||
fbf6329500 | |||
41549443c3 | |||
92630af4e1 | |||
4db633da16 | |||
dac02f13ae | |||
1a52dec1c2 | |||
be1ca51162 | |||
768e20bb79 | |||
26b9b15de8 | |||
42713095b6 | |||
3acafeca38 | |||
7ca75c8c5a | |||
c00ad454a9 | |||
16d04eb4d3 | |||
816845f271 | |||
12eeda8d33 | |||
3d622c2ef1 | |||
21a6767c6f | |||
7a7326ec09 | |||
9b3af4e217 | |||
cee0114f81 | |||
03399aedf0 | |||
2739b94bd8 | |||
c720441d62 | |||
00b5898fe0 | |||
0d0940b7a5 | |||
f28c949ac6 | |||
63317d6ac8 | |||
6406ba831f | |||
7a7575964a | |||
d75c833717 | |||
40344b57d9 | |||
6fc26d1da3 | |||
a012a0e418 | |||
bf1a2f3059 | |||
ca316b4e6d | |||
1fb5c581c9 | |||
efa64b451a | |||
38059ea6b9 | |||
c2110622ca | |||
0452959b85 | |||
0eca8389b6 | |||
66e043137b | |||
d684654625 | |||
7749f6b20f | |||
15c9c0ae3e | |||
74fddc2ada | |||
cff866ecdc | |||
e952c02c83 | |||
546983c6ba | |||
c7134564a3 | |||
984a3573eb | |||
defe94a2b2 | |||
e23c8c4b46 | |||
7941ff487a | |||
7b7df33a0f | |||
68b04f2511 | |||
db3e017a7d | |||
c21d45a79e | |||
6defb686bb | |||
f68796dae1 | |||
b1872bcb95 | |||
3006f4d2c1 | |||
7f88a38219 | |||
aeb2487c70 | |||
e42e50dd39 | |||
f4572b9720 | |||
7646f3a845 | |||
e4e5b1e4f6 | |||
a481518470 | |||
2435ebf16e | |||
414fa70e5d | |||
f255d4c141 | |||
4513bb529b | |||
5907132062 | |||
69bf313f18 | |||
fe8b0a6b2b | |||
abcfd79f2f | |||
41e3b078ec | |||
4eb2f92c1f | |||
9bfb5bf681 | |||
473ad2947c | |||
ee28f6ad84 | |||
11bebd42ac | |||
49b4ca67e0 | |||
3282f762df | |||
d335106b46 | |||
cefa01f7ec | |||
b7ba2b3306 | |||
03d5152e7c | |||
af3b7f2613 | |||
1405841565 | |||
211d2dc0d6 | |||
82f431465f | |||
247afe56ce | |||
91e874eee5 | |||
ff67c3660b | |||
58c580b9ca | |||
a9da151026 | |||
83c72d0dbb | |||
2c31367851 | |||
3b618f3a2c | |||
4c5bc6232d | |||
694835bdac | |||
c8b75c19da | |||
c0181aa83a | |||
c5b615ae2a | |||
54cbd56f42 | |||
c8914a109e | |||
62d0767ceb | |||
8509bccc4f | |||
4ce53a3d76 | |||
8024c01a82 | |||
1b380c3fdb | |||
06b67bd292 | |||
8a1087f601 | |||
ff09d6515c | |||
ebe85d8e14 | |||
5dc27ac46a | |||
1dcc8ee761 | |||
ec69f9ac07 | |||
f789f60e22 | |||
32e3f07d57 | |||
9ea41ab3ce | |||
4b8d062862 | |||
d9408029f3 | |||
9fe0406078 | |||
5a4fe5d5da | |||
e6af9b4b73 | |||
361f9231d8 | |||
4215932550 | |||
29da523579 | |||
fbb4d7cfde | |||
3ea453a07f | |||
984e762a53 | |||
1592aa7117 | |||
62b4522c94 | |||
8b86751c95 | |||
afa380e336 | |||
feebff9077 | |||
028b50ff99 | |||
559e81c3fe | |||
4da6b98437 | |||
5b2409c76f | |||
ff027d172e | |||
3f23290a46 | |||
f1a10d32e6 | |||
a71f40e873 | |||
7f449319cd | |||
ab5c8ea698 | |||
68cfa9360b | |||
f627e3d994 | |||
7c870548d9 | |||
57ccc41547 | |||
988ba45197 | |||
df6606041b | |||
3ae27b466f | |||
69f5e21435 | |||
6da73c612a | |||
e1b1c1492f | |||
6ca13c4fce | |||
b474567d20 | |||
c07170902e | |||
0f201d2f4b | |||
b875d6f183 | |||
831b92239d | |||
66b91c22dd | |||
1242c0689f | |||
4386d02526 | |||
3ba521f8cc | |||
85bb818ae6 | |||
be7e2aa8fe | |||
7f71f6e3f1 | |||
a94d23e2ae | |||
133c255ce2 | |||
863e27ff9b | |||
5c63e6ae12 | |||
10dd36569d | |||
be5985fb6a | |||
0d7f169613 | |||
eaddcb83ab | |||
9a6885f124 | |||
7284ee818b | |||
20964454c4 | |||
d7670929d1 | |||
58f0761423 | |||
3f28bc09bc | |||
323895f0ab | |||
6efa734e81 | |||
47d64af737 | |||
4a2b91ce07 | |||
080a77cc73 | |||
9b874b0061 | |||
ff8a2ed538 | |||
251eafe103 | |||
64b604c9ac | |||
72fc5f9874 | |||
71dcdf0ca2 | |||
e23fc987a7 | |||
36dba1a36f | |||
1b1547d4b6 | |||
8008482592 | |||
6d1a7fe438 | |||
90c58b0498 | |||
c91bb71700 | |||
3d09c45205 | |||
f1e41d883c | |||
4f783ec8e4 | |||
3d35e84953 | |||
e80bc8b584 | |||
2848b39479 | |||
7ee9be200c | |||
94cdd740ad | |||
9130687164 | |||
2f52f47463 | |||
01866f4802 | |||
fa8ac0f2e4 | |||
e9a909ed20 | |||
8808447963 | |||
056b496189 | |||
11b374ea75 | |||
f8f9744786 | |||
6f6888d638 | |||
995430b76f | |||
d4a5ec4e14 | |||
c7dce059f8 | |||
2f4e3f2153 | |||
a37c5646b6 | |||
ddc9c8f62f | |||
1b06fc71cf | |||
e65a3bfeab | |||
b9ceabcc07 | |||
35be3bfb9b | |||
572c8efbc7 | |||
b1b3e2369b | |||
dc72bb629e | |||
a724706817 | |||
84989116ef | |||
6c4efe4a1c | |||
8596d70b79 | |||
db6c9b2700 | |||
a33602ccf6 | |||
988987ddbe | |||
309e66a6de | |||
7d8cfc0382 | |||
5cbae5d3f7 | |||
9b630c4ef7 | |||
befcbabe27 | |||
4cfb0ade88 | |||
a6f528537b | |||
dfc82a517d | |||
29f421686f | |||
c11299076f | |||
1cb2ef565e | |||
2de07d04a8 | |||
75e064dd1d | |||
5f0091ee25 | |||
d2c0e656d0 | |||
522b21862b | |||
ccf66dbd50 | |||
6e30ab0355 | |||
568c764e3c | |||
d508e8ae31 | |||
ded346e34a | |||
edb8eddce1 | |||
abd3641da4 | |||
7e1165d012 | |||
461754e591 | |||
e649330dbc | |||
baec324811 | |||
91c430d9e2 | |||
efd853d519 | |||
f717b0eae4 | |||
d76d21a1f2 | |||
712450d717 | |||
b9d93c9d33 | |||
c7ca51cd65 | |||
20b793620a | |||
9bed303d34 | |||
f4ed171f85 | |||
8a3ccdb196 | |||
41765d133f | |||
482ea1b186 | |||
3bba7f9d23 | |||
7e5e2baf92 | |||
53c70e6cd1 | |||
4bfb87ea74 | |||
86e12c7d40 | |||
eb5449adf8 | |||
19eeec9fc8 | |||
449f5f5be3 | |||
bc5a1b52b7 | |||
fc7f37767f | |||
38dbdd02ae | |||
7bb3fa74ce | |||
a33660d32c | |||
ef842d1f3f | |||
e5c2a0a87b | |||
817ffe8fd0 | |||
5b582d45ba | |||
6a303532f4 | |||
c75abb7cb9 | |||
8282d76b87 | |||
79f3866c4c | |||
6dcf3f25e9 | |||
e80acea63f | |||
640639264d | |||
3ccdd2585c | |||
2c4b55c692 | |||
70a3b25d54 | |||
d053baef03 | |||
629c586014 | |||
32a5cca878 | |||
911c705b59 | |||
594c8d72b8 | |||
7ea5232b22 | |||
be12d61795 | |||
925340eb3d | |||
e4b03b3f71 | |||
9ab6df99b1 | |||
51519a55ef | |||
059455929b | |||
8a1df4438e | |||
cbf6e46e35 | |||
727b1bd63b | |||
363b8d74ae | |||
b31ecd6583 | |||
563914a0ef | |||
1e8adbb240 | |||
4b1f89a561 | |||
1a4a0ea5b8 | |||
f781028b08 | |||
56e8ad4f17 | |||
62c34ae612 | |||
26123b0a93 | |||
4023464a13 | |||
0c92f354c5 | |||
676723c8bd | |||
2f4d5afaea | |||
d0abceb08d | |||
8b165e93e1 | |||
321969eb85 | |||
85ec90849e | |||
96451bc5b7 | |||
311cbf55ef | |||
0258b256f2 | |||
c615de97c4 | |||
e29a7bf146 | |||
b665c243f0 | |||
bea1c9ed61 | |||
0e6bdaa9c9 | |||
7925689618 | |||
0e818c8d73 | |||
791441ec86 | |||
401de9147c | |||
563e10fa92 | |||
a22c34d8c2 | |||
e549f8ae61 | |||
0ac23d0646 | |||
814d3892f2 | |||
07d1306a35 | |||
5950055cca | |||
d6dd468e84 | |||
9a221a01ab | |||
601a4038f4 | |||
2a78a29b08 | |||
e90d97b813 | |||
d020d59b11 | |||
5d6d52a465 | |||
ebb3f8137e | |||
af7d275c27 | |||
2b01a6006c | |||
9f3940746a | |||
9f729b3bb3 | |||
2376fb5834 | |||
0a1507599b | |||
42bb01c416 | |||
cfb0ae7428 | |||
6b30f44da0 | |||
a7f89ac58f | |||
38711f04bc | |||
78fd99c26e | |||
cae10d4611 | |||
40233dbf87 | |||
35865e46f0 | |||
ea565d8f71 | |||
859a3f4015 | |||
ebcb37cbed | |||
1bdf9a4987 | |||
d7a9cb2168 | |||
8890e13ccb | |||
87e1844f04 | |||
388030c6ec | |||
d5bd407802 | |||
ba4dc2ed54 | |||
c982e64996 | |||
0425939668 | |||
48b804b765 | |||
246ae6e6bc | |||
efa5b65e45 | |||
f4f6ee5055 | |||
1a630bcb4d | |||
600fef21f6 | |||
b779ee79a5 | |||
08537944ae | |||
004b3641eb | |||
b6be05a931 | |||
191cc071c2 | |||
9e52c46ad3 | |||
21f7662a77 | |||
d4d7f92df8 | |||
a3180fd70d | |||
3dc4f8e87a | |||
64393d92a5 | |||
1fbd405e41 | |||
f711aa1b58 | |||
e2e527ce44 | |||
bb7f48c021 | |||
ad9b64e7ae | |||
ef2ee6d00d | |||
2d259c4edc | |||
b286e3ae09 | |||
ec3e193672 | |||
40a2fcd81e | |||
7e876bad7e | |||
aefa3b102c | |||
4d1f295a26 | |||
56a31faf7e | |||
f3afef01b0 | |||
ea38655c48 | |||
972d06b492 | |||
8538489136 | |||
4f28464b99 | |||
049e111797 | |||
96199c4b12 | |||
cf23789edf | |||
48724e5b08 | |||
40c778d244 | |||
ff0c44ecfc | |||
828cc15ea3 | |||
bbbe55b706 | |||
cd98bdec9b | |||
59767bddfe | |||
035ae40b97 | |||
f7603bfdfc | |||
754201a9a2 | |||
d0af7e4781 | |||
ecf0bf8cdd | |||
85bafb3eef | |||
efe378e94f | |||
614cb74d47 | |||
df4190321e | |||
56c3574a2b | |||
51b11c7035 | |||
564693cf22 | |||
50a6bed92f | |||
ef54b3cf2e | |||
ebf06250b1 | |||
56f9c22ac6 | |||
384242974b | |||
7717d95cab | |||
5b69a32c11 | |||
24abf51c8c | |||
80c5092dc1 | |||
15ffa4d98b | |||
4935878f73 | |||
440782e9cf | |||
f304220463 | |||
02a5aaf5d8 | |||
e84641c13c | |||
278b6b6a20 | |||
d369c0a74c | |||
ab9f97598c | |||
2814841226 | |||
a7d55a52f3 | |||
d436b7b339 | |||
f183d38bb3 | |||
2353b36709 | |||
00db6e7dc1 | |||
eb479c4684 | |||
68413605e9 | |||
02bd5d71d0 | |||
97a851a848 | |||
f503794e09 | |||
d0ee5fa23a | |||
0ccf0f8d7a | |||
719f7c8f9e | |||
828e30a248 | |||
6beb7208af | |||
2d342a2415 | |||
a2017fc353 | |||
709c3d9b55 | |||
950867d032 | |||
65caa531c5 | |||
64addc85ee | |||
aa02261248 | |||
6d447033c9 | |||
c888f589d0 | |||
bb6eb87313 | |||
813143237b | |||
91c149caf8 | |||
3e619e47b2 | |||
e0576c889b | |||
3c03281b78 | |||
1d0c43e45d | |||
982d923553 | |||
4697d774f4 | |||
c19bc6b4b3 | |||
9c15cb55c8 | |||
73b974ddb2 | |||
c38e70e25d | |||
60096a94c9 | |||
c155f76550 | |||
9827ed30bb | |||
49054dae27 | |||
46f1f78529 | |||
5b7c62685d | |||
0acb9cf7a9 | |||
233a29bfef | |||
d6ec275778 | |||
291a650337 | |||
9d4476b04a | |||
871e0721b9 | |||
f1ab24c439 | |||
05c053a44d | |||
966a14b1b3 | |||
c00751d26a | |||
9fe329d542 | |||
96f2e8acb5 | |||
37dd51a119 | |||
e962f0ab83 | |||
a7f17f91d6 | |||
20cdd25e70 | |||
a79f839693 | |||
c7b68a40e4 | |||
f414b4ee9a | |||
ea908d57b5 | |||
bdbd15e7d9 | |||
00ae5a1a1f | |||
48f7e15be9 | |||
99d3a241a0 | |||
eea9643d7e | |||
d66f79e7b3 | |||
a5193b18d8 | |||
ec408c2dea | |||
cb79c616ee | |||
c7d9be597f | |||
c77542195e | |||
824f5d6396 | |||
0b2235793b | |||
559b92a8f9 | |||
8c7c373097 | |||
52f1392cc2 | |||
c21cc6c3e9 | |||
5cba27b482 | |||
4fe8a2aa9d | |||
27b3884e4d | |||
b54ff84adb | |||
8e8d09bbda | |||
0f78442cca | |||
9578c4ba33 | |||
9431f7b34e | |||
460d4888eb | |||
c8b183f057 | |||
27b0169e5f | |||
e47d8846a4 | |||
4f846f2a4a | |||
2246c625ce | |||
4e97012466 | |||
b7c0ad2d84 | |||
065977af37 | |||
4ff7f0a7bd | |||
2882c9aee2 | |||
96ad7c5886 | |||
c41b208ecb | |||
5f446a1f39 | |||
62223f3053 | |||
ce80a592de | |||
4e002ff342 | |||
9260fcb450 | |||
19b4f87ec1 | |||
2a9607b5b4 | |||
0bc3fe0617 | |||
375818b496 | |||
98d82248df | |||
d22263293f | |||
dbf7157ac6 | |||
dbd8d98223 | |||
aedaa98ecf | |||
252878dd74 | |||
2dc7fa7fda | |||
d50c00b8e4 | |||
aef9c9883d | |||
cf825676d3 | |||
af56f33b83 | |||
512cded8aa | |||
4af9e2545f | |||
7ea0917b90 | |||
6ed9059c34 | |||
33ec69bc17 | |||
f07ce0bbf4 | |||
d2f9816714 | |||
58305b5970 | |||
0b0a185fef | |||
d9743c2fa8 | |||
71b7c22aa8 | |||
2237b7d687 | |||
435fe309bd | |||
464002a03b | |||
fe7e7f4085 | |||
5a0c42a351 | |||
fe3a299b32 | |||
8712c0f2e0 | |||
c495035da0 | |||
0286749ffc | |||
54b43c76e1 | |||
0ffe150fdc | |||
e630c694b3 | |||
853219dca5 | |||
63a5e25e42 | |||
0fe51ffcb2 | |||
b8a750aa64 | |||
26dfed5853 | |||
259b428d2d | |||
29dd14933e | |||
98013466be | |||
27dd0a6ede | |||
e40deff1b5 | |||
6f4b70b7ed | |||
6bf962a670 | |||
896f6b5000 | |||
8011c54631 | |||
591e9b0be0 | |||
b6f6bb0894 | |||
d14f343481 | |||
afc50719ce | |||
257b3f075d | |||
1973597eb2 | |||
a87ecc2c99 | |||
a4eeb5782e | |||
36f537144a | |||
ad047110b4 | |||
32ac881d3d | |||
5fba4d8e76 | |||
d836231737 | |||
bfcacc16a2 | |||
862d04f4d5 | |||
d1699482bf | |||
622289ce2c | |||
0859026fcc | |||
c19c55d2c2 | |||
f21b1bc85b | |||
9ba31e8c3c | |||
fe71e59524 | |||
ddd85688ce | |||
6ca91e78db | |||
0008090360 | |||
8cf779d5b8 | |||
b81086ab7a | |||
6b2eab89d8 | |||
3cf4eb7b48 | |||
fd44b3b649 | |||
ce4eaec827 | |||
456e424d4d | |||
2f3b6a2753 | |||
c49a0225d7 | |||
c1e47885e0 | |||
b2a09b512f | |||
75bf33d64e | |||
33b44c1612 | |||
dc7f199345 | |||
bf77d76a75 | |||
26bdca5f30 | |||
491b774dd9 | |||
65e004f0c1 | |||
8348db2067 | |||
5dfe811a46 | |||
10f76962dd | |||
6377bb2d81 | |||
a012896665 | |||
8c5859aacd | |||
cf267cc84a | |||
578cc1530b | |||
516658ad56 | |||
d37e78057c | |||
2eabf1aba8 | |||
67b4e48c74 | |||
2c0921c8e6 | |||
2642571cf9 | |||
b14d657ad6 | |||
7d010f1186 | |||
dec9c3db49 | |||
326c4492d0 | |||
b1270309c0 | |||
607e01925e | |||
700474f80d | |||
37655b357f | |||
3ae5b5d8d5 | |||
f7bd5ae327 | |||
d307ecbde0 | |||
fa8d0bc9a6 | |||
b34b01e2da | |||
b32d6645aa | |||
594861024d | |||
22fd752afc | |||
5c57e61f84 | |||
d3479b4e45 | |||
5eaeed2679 | |||
bea22bef53 | |||
06d055c37d | |||
009faac447 | |||
4444063bcb | |||
826b9e9a99 | |||
9905654ef0 | |||
00549cc011 | |||
768f3c8f8f | |||
096a627944 | |||
63892f8ab4 | |||
3094d216a8 | |||
c1fd61850b | |||
5e95a6272d | |||
111c80d049 | |||
e6aad63047 | |||
e7fa73d145 | |||
bf685faf1d | |||
efcd318100 | |||
9cbb307fcc | |||
a868692b7a | |||
4900697d4a | |||
60bc688ce2 | |||
ab7d4f9f25 | |||
9a937891a8 | |||
3a27a33d8c | |||
e5005598e2 | |||
fbaea25fa3 | |||
9ce032decf | |||
01ab5e0c00 | |||
1412b40c4e | |||
e0ac5081ab | |||
dd4ee37179 | |||
344f7f036d | |||
2e02a3dfad | |||
3235f9bd7a | |||
e6cee96a9d | |||
11d902ff21 | |||
b8196aaa5a | |||
591fc0abad | |||
eb25eb43d7 | |||
df6b1c0815 | |||
82d9a71e67 | |||
d46c4e7387 | |||
abf2f531da | |||
f36b13f9ae | |||
4775093376 | |||
531e240a37 | |||
152b91685c | |||
2b0e8385f1 | |||
36b3242f4a | |||
8ca113c87b | |||
d3fd3938c7 | |||
8f0bbec5da | |||
6e95fd0fb9 | |||
dd842d54f0 | |||
efb48bf9ea | |||
d1d0310200 | |||
fdeb873536 | |||
8583aa0632 | |||
7682745402 | |||
2eb0b537f1 | |||
6d3ebf90c1 | |||
ed8b4180f8 | |||
4ad34920b7 | |||
ede6a32537 | |||
078d4908c2 | |||
c9135953f7 | |||
5259f30752 | |||
2223cfb6b2 | |||
345ce6db6d | |||
7accb91195 | |||
2bb9a78d2f | |||
f303306935 | |||
c82ad9711b | |||
41acda6a06 | |||
5d7ef7ab58 | |||
29f7f1a240 | |||
6b0d777bd7 | |||
455e66f74d | |||
36af1643a4 | |||
3a022c4d2a | |||
e50a6edbed | |||
31728ea253 | |||
5289ea8e1c | |||
d808b287a7 | |||
5ad7fd8a15 | |||
74fbc715e9 | |||
1385a5d702 | |||
e08ad990a8 | |||
35d987430a | |||
bb48068408 | |||
75d62723b6 | |||
02222c8681 | |||
c3800c4559 | |||
0e033131b2 | |||
0be6f31611 | |||
e8a8b73ad0 | |||
953c6806ce | |||
1cf68c696e | |||
6d354674b2 | |||
e598faad28 | |||
137b9a06cb | |||
c43f04da52 | |||
1941721070 | |||
9f282952cd | |||
09b81017d0 | |||
4f58979096 | |||
898104ea2c | |||
7d15eeda88 | |||
cba3f77272 | |||
91dffc45ff | |||
47eb46e700 | |||
8271ddc78e | |||
6b08545ef9 | |||
9cddfb4ce7 | |||
19b26e1c5e | |||
936fffd0a1 | |||
2f24d062b3 | |||
4e373d4ab6 | |||
c01d3d9f67 | |||
d2f344b83f | |||
d7f5a44b45 | |||
0a9b98e1aa | |||
fd188870e8 | |||
c28e6ac22e | |||
9381bd8ddb | |||
454fc76e8d | |||
ba963b0360 | |||
19d3ed47c9 | |||
0757295213 | |||
76c677a6b1 | |||
ce8842b52f | |||
a039fe3223 | |||
a669b2148f | |||
53a7d87b03 | |||
388ab4f3b1 | |||
567713b7ba | |||
9547805ec2 | |||
89040e0237 | |||
dd657a9e88 | |||
fe21bb1702 | |||
a01d352925 | |||
e1fb07989f | |||
b0d6be1929 | |||
a2e0c66dc8 | |||
fe028c3ac1 | |||
92ef5805b8 | |||
e30f3b2035 | |||
cdcaba651c | |||
63aff461ed | |||
54565e2228 | |||
cce6d3fcbe | |||
26809a33c6 | |||
030594ccae | |||
396470886c | |||
0408a2808c | |||
14f9347311 | |||
40747603e8 | |||
608ba89c7c | |||
f34d4833a8 | |||
051a1226c0 | |||
5b2350c01c | |||
0ffc114005 | |||
ff25a4faa5 | |||
e73b12cd76 | |||
7a2f209430 | |||
0174e9b423 | |||
794571c7e1 | |||
c34a4f2613 | |||
f648ecf0b8 | |||
e1cc557bec | |||
2310b7f479 | |||
e64bb9c7b9 | |||
af98f80db0 | |||
8a704776d2 | |||
67a205cae7 | |||
1fb1f50756 | |||
50049113b5 | |||
49694a53fd | |||
ead04d0764 | |||
47099d0468 | |||
abbd620220 | |||
303b025aee | |||
1421b06df7 | |||
1e37282e06 | |||
7b992ed254 | |||
deba94d69c | |||
5e09c27a0d | |||
31563f53ec | |||
a967e560c6 | |||
c4427f7bb9 | |||
a563659eca | |||
caca11d807 | |||
c79d68d83e | |||
7af63f4b0c |
71
.cspell.json
Normal file
71
.cspell.json
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// cSpell Settings
|
||||||
|
{
|
||||||
|
// Version of the setting file. Always 0.2
|
||||||
|
"version": "0.2",
|
||||||
|
// language - current active spelling language
|
||||||
|
"language": "en_US",
|
||||||
|
"dictionaries": [
|
||||||
|
"en_US",
|
||||||
|
"typescript",
|
||||||
|
"softwareTerms",
|
||||||
|
"fonts",
|
||||||
|
"npm"
|
||||||
|
],
|
||||||
|
// words - list of words to be always considered correct
|
||||||
|
"words": [
|
||||||
|
"Abjad",
|
||||||
|
"aiueo",
|
||||||
|
"ATLEAST",
|
||||||
|
"chosung",
|
||||||
|
"clippy",
|
||||||
|
"datas",
|
||||||
|
"docsify",
|
||||||
|
"dolan",
|
||||||
|
"falsey",
|
||||||
|
"Initializable",
|
||||||
|
"iroha",
|
||||||
|
"jsonify",
|
||||||
|
"jszip",
|
||||||
|
"NUMPAGES",
|
||||||
|
"odttf",
|
||||||
|
"ooxml",
|
||||||
|
"panose",
|
||||||
|
"rels",
|
||||||
|
"rsid",
|
||||||
|
"twip",
|
||||||
|
"twips",
|
||||||
|
"Xmlable",
|
||||||
|
"xmlified",
|
||||||
|
"xmlify",
|
||||||
|
"Xmlifyed"
|
||||||
|
],
|
||||||
|
"ignoreRegExpList": [
|
||||||
|
"/\"w:.+\"/",
|
||||||
|
"/\"s:.+\"/",
|
||||||
|
"/\"a:.+\"/",
|
||||||
|
"/\"pic:.+\"/",
|
||||||
|
"/\"xmlns:.+\"/",
|
||||||
|
"/\"vt:.+\"/",
|
||||||
|
"/[^\\s]{40,}/",
|
||||||
|
"/<xsd:.+/>/",
|
||||||
|
"/[A-Z_]+ = \".+\"/",
|
||||||
|
"/XmlAttributeComponent<{[^}]+}>/g",
|
||||||
|
"/xmlKeys = {[^}]+}/g",
|
||||||
|
"/\\.to\\.deep\\.equal\\({[^)]+}\\)/g",
|
||||||
|
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||||
|
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
||||||
|
"/<element name=\"[a-z]+\"/gi",
|
||||||
|
"/<attribute name=\"[a-z]+\"/gi"
|
||||||
|
],
|
||||||
|
"ignorePaths": [
|
||||||
|
"package.json",
|
||||||
|
"docs/api"
|
||||||
|
],
|
||||||
|
"allowCompoundWords": true,
|
||||||
|
// flagWords - list of words to be always considered incorrect
|
||||||
|
// This is useful for offensive words and common spelling errors.
|
||||||
|
// For example "hte" should be "the"
|
||||||
|
"flagWords": [
|
||||||
|
"hte"
|
||||||
|
]
|
||||||
|
}
|
272
.eslintrc.js
Normal file
272
.eslintrc.js
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
/*
|
||||||
|
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
|
||||||
|
https://github.com/typescript-eslint/tslint-to-eslint-config
|
||||||
|
|
||||||
|
It represents the closest reasonable ESLint configuration to this
|
||||||
|
project's original TSLint configuration.
|
||||||
|
|
||||||
|
We recommend eventually switching this configuration to extend from
|
||||||
|
the recommended rulesets in typescript-eslint.
|
||||||
|
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
|
||||||
|
|
||||||
|
Happy linting! 💖
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
extends: "eslint:recommended",
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
es6: true,
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
parser: "@typescript-eslint/parser",
|
||||||
|
parserOptions: {
|
||||||
|
project: "tsconfig.json",
|
||||||
|
sourceType: "module",
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
"eslint-plugin-import",
|
||||||
|
"eslint-plugin-no-null",
|
||||||
|
"eslint-plugin-unicorn",
|
||||||
|
"eslint-plugin-jsdoc",
|
||||||
|
"eslint-plugin-prefer-arrow",
|
||||||
|
"@typescript-eslint",
|
||||||
|
"functional",
|
||||||
|
],
|
||||||
|
root: true,
|
||||||
|
rules: {
|
||||||
|
"no-undef": "off",
|
||||||
|
"no-extra-boolean-cast": "off",
|
||||||
|
"no-alert": "error",
|
||||||
|
"no-self-compare": "error",
|
||||||
|
"no-unreachable-loop": "error",
|
||||||
|
"no-template-curly-in-string": "error",
|
||||||
|
"no-unused-private-class-members": "error",
|
||||||
|
"no-extend-native": "error",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-implied-eval": "error",
|
||||||
|
"no-iterator": "error",
|
||||||
|
"no-lone-blocks": "error",
|
||||||
|
"no-loop-func": "error",
|
||||||
|
"no-new-object": "error",
|
||||||
|
"no-proto": "error",
|
||||||
|
"no-useless-catch": "error",
|
||||||
|
"one-var-declaration-per-line": "error",
|
||||||
|
"prefer-arrow-callback": "error",
|
||||||
|
"prefer-destructuring": "error",
|
||||||
|
"prefer-exponentiation-operator": "error",
|
||||||
|
"prefer-promise-reject-errors": "error",
|
||||||
|
"prefer-regex-literals": "error",
|
||||||
|
"prefer-spread": "error",
|
||||||
|
"prefer-template": "error",
|
||||||
|
"require-await": "error",
|
||||||
|
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||||
|
"@typescript-eslint/array-type": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
default: "array",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/ban-types": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
types: {
|
||||||
|
Object: {
|
||||||
|
message: "Avoid using the `Object` type. Did you mean `object`?",
|
||||||
|
},
|
||||||
|
Function: {
|
||||||
|
message: "Avoid using the `Function` type. Prefer a specific function type, like `() => void`.",
|
||||||
|
},
|
||||||
|
Boolean: {
|
||||||
|
message: "Avoid using the `Boolean` type. Did you mean `boolean`?",
|
||||||
|
},
|
||||||
|
Number: {
|
||||||
|
message: "Avoid using the `Number` type. Did you mean `number`?",
|
||||||
|
},
|
||||||
|
String: {
|
||||||
|
message: "Avoid using the `String` type. Did you mean `string`?",
|
||||||
|
},
|
||||||
|
Symbol: {
|
||||||
|
message: "Avoid using the `Symbol` type. Did you mean `symbol`?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/consistent-type-assertions": "error",
|
||||||
|
"@typescript-eslint/dot-notation": "error",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
allowExpressions: true,
|
||||||
|
allowTypedFunctionExpressions: true,
|
||||||
|
allowHigherOrderFunctions: false,
|
||||||
|
allowDirectConstAssertionInArrowFunctions: true,
|
||||||
|
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/explicit-member-accessibility": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
accessibility: "explicit",
|
||||||
|
overrides: {
|
||||||
|
accessors: "explicit",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/explicit-module-boundary-types": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
allowArgumentsExplicitlyTypedAsAny: true,
|
||||||
|
allowDirectConstAssertionInArrowFunctions: true,
|
||||||
|
allowHigherOrderFunctions: false,
|
||||||
|
allowTypedFunctionExpressions: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/naming-convention": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
selector: ["objectLiteralProperty"],
|
||||||
|
leadingUnderscore: "allow",
|
||||||
|
format: ["camelCase", "PascalCase"],
|
||||||
|
filter: {
|
||||||
|
regex: "(^[a-z]+:.+)|_attr|[0-9]",
|
||||||
|
match: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-empty-function": "error",
|
||||||
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
|
"@typescript-eslint/no-namespace": "error",
|
||||||
|
"@typescript-eslint/no-parameter-properties": "off",
|
||||||
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
|
"@typescript-eslint/no-shadow": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
hoist: "all",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-this-alias": "error",
|
||||||
|
"@typescript-eslint/no-unused-expressions": "error",
|
||||||
|
"@typescript-eslint/no-use-before-define": "off",
|
||||||
|
"@typescript-eslint/no-var-requires": "error",
|
||||||
|
"@typescript-eslint/prefer-for-of": "error",
|
||||||
|
"@typescript-eslint/prefer-function-type": "error",
|
||||||
|
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||||
|
"@typescript-eslint/prefer-readonly": "error",
|
||||||
|
"@typescript-eslint/triple-slash-reference": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
path: "always",
|
||||||
|
types: "prefer-import",
|
||||||
|
lib: "always",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/typedef": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
parameter: true,
|
||||||
|
propertyDeclaration: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@typescript-eslint/unified-signatures": "error",
|
||||||
|
"arrow-body-style": "error",
|
||||||
|
complexity: "off",
|
||||||
|
"consistent-return": "error",
|
||||||
|
"constructor-super": "error",
|
||||||
|
curly: "error",
|
||||||
|
"dot-notation": "off",
|
||||||
|
eqeqeq: ["error", "smart"],
|
||||||
|
"guard-for-in": "error",
|
||||||
|
"id-denylist": ["error", "any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"],
|
||||||
|
"id-match": "error",
|
||||||
|
"import/no-default-export": "error",
|
||||||
|
"import/no-extraneous-dependencies": "off",
|
||||||
|
"import/no-internal-modules": "off",
|
||||||
|
"import/order": "error",
|
||||||
|
indent: "off",
|
||||||
|
"jsdoc/check-alignment": "error",
|
||||||
|
"jsdoc/check-indentation": "off",
|
||||||
|
"jsdoc/newline-after-description": "error",
|
||||||
|
"max-classes-per-file": "off",
|
||||||
|
"max-len": "off",
|
||||||
|
"new-parens": "error",
|
||||||
|
"no-bitwise": "error",
|
||||||
|
"no-caller": "error",
|
||||||
|
"no-cond-assign": "error",
|
||||||
|
"no-console": "error",
|
||||||
|
"no-debugger": "error",
|
||||||
|
"no-duplicate-case": "error",
|
||||||
|
"no-duplicate-imports": "error",
|
||||||
|
"no-empty": "error",
|
||||||
|
"no-empty-function": "off",
|
||||||
|
"no-eval": "error",
|
||||||
|
"no-extra-bind": "error",
|
||||||
|
"no-fallthrough": "off",
|
||||||
|
"no-invalid-this": "off",
|
||||||
|
"no-multiple-empty-lines": "error",
|
||||||
|
"no-new-func": "error",
|
||||||
|
"no-new-wrappers": "error",
|
||||||
|
"no-null/no-null": "error",
|
||||||
|
"no-param-reassign": "error",
|
||||||
|
"no-redeclare": "error",
|
||||||
|
"no-return-await": "error",
|
||||||
|
"no-sequences": "error",
|
||||||
|
"no-shadow": "off",
|
||||||
|
"no-sparse-arrays": "error",
|
||||||
|
"no-throw-literal": "error",
|
||||||
|
"no-trailing-spaces": "error",
|
||||||
|
"no-undef-init": "error",
|
||||||
|
"no-underscore-dangle": ["error", { allow: ["_attr"] }],
|
||||||
|
"no-unsafe-finally": "error",
|
||||||
|
"no-unused-expressions": "off",
|
||||||
|
"no-unused-labels": "error",
|
||||||
|
"no-use-before-define": "off",
|
||||||
|
"no-useless-constructor": "error",
|
||||||
|
"no-var": "error",
|
||||||
|
"object-shorthand": "off",
|
||||||
|
"one-var": ["error", "never"],
|
||||||
|
"prefer-arrow/prefer-arrow-functions": "error",
|
||||||
|
"prefer-const": "error",
|
||||||
|
"prefer-object-spread": "error",
|
||||||
|
radix: "error",
|
||||||
|
"space-in-parens": ["error", "never"],
|
||||||
|
"spaced-comment": [
|
||||||
|
"error",
|
||||||
|
"always",
|
||||||
|
{
|
||||||
|
markers: ["/"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"unicorn/filename-case": "error",
|
||||||
|
"unicorn/prefer-ternary": "error",
|
||||||
|
"use-isnan": "error",
|
||||||
|
"valid-typeof": "off",
|
||||||
|
"functional/immutable-data": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
assumeTypes: true,
|
||||||
|
ignoreImmediateMutation: true,
|
||||||
|
ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"functional/prefer-property-signatures": "error",
|
||||||
|
"functional/no-mixed-types": "error",
|
||||||
|
// TODO: Deprecated. Use prefer-immutable-types and type-declaration-immutability instead
|
||||||
|
"functional/prefer-readonly-type": "error",
|
||||||
|
// "functional/prefer-immutable-types": "error",
|
||||||
|
// "functional/type-declaration-immutability": "error",
|
||||||
|
"no-unused-vars": ["error", { argsIgnorePattern: "^[_]+$" }],
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ["*.spec.ts"],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-unused-expressions": "off",
|
||||||
|
"@typescript-eslint/dot-notation": "off",
|
||||||
|
"prefer-destructuring": "off",
|
||||||
|
"@typescript-eslint/explicit-function-return-type": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# https://prettier.io/docs/en/options.html#end-of-line
|
||||||
|
* text=auto eol=lf
|
20
.github/workflows/default.yml
vendored
20
.github/workflows/default.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: Archive Production Artifact
|
- name: Archive Production Artifact
|
||||||
@ -30,11 +30,11 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test.coverage
|
run: npm run test.coverage
|
||||||
- name: Codecov
|
- name: Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
with:
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
verbose: true
|
verbose: true
|
||||||
@ -45,7 +45,7 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
prettier:
|
prettier:
|
||||||
@ -55,6 +55,16 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Prettier
|
- name: Prettier
|
||||||
run: npm run style
|
run: npm run style
|
||||||
|
cspell:
|
||||||
|
name: CSpell
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci --force
|
||||||
|
- name: Prettier
|
||||||
|
run: npm run cspell
|
||||||
|
154
.github/workflows/demos.yml
vendored
154
.github/workflows/demos.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: Archive Production Artifact
|
- name: Archive Production Artifact
|
||||||
@ -31,7 +31,7 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Download Artifact
|
- name: Download Artifact
|
||||||
uses: actions/download-artifact@master
|
uses: actions/download-artifact@master
|
||||||
with:
|
with:
|
||||||
@ -202,13 +202,14 @@ jobs:
|
|||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
- name: Run Demo
|
- name: Run Demo
|
||||||
run: npm run ts-node -- ./demo/19-export-to-base64.ts
|
run: npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
- name: Extract Word Document
|
# Base 64 No longer works, abruptly. Node issue?
|
||||||
run: npm run extract
|
# - name: Extract Word Document
|
||||||
- name: Validate XML
|
# run: npm run extract
|
||||||
uses: ChristophWurst/xmllint-action@v1
|
# - name: Validate XML
|
||||||
with:
|
# uses: ChristophWurst/xmllint-action@v1
|
||||||
xml-file: build/extracted-doc/word/document.xml
|
# with:
|
||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
# xml-file: build/extracted-doc/word/document.xml
|
||||||
|
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
- name: Run Demo
|
- name: Run Demo
|
||||||
run: npm run ts-node -- ./demo/20-table-cell-borders.ts
|
run: npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
- name: Extract Word Document
|
- name: Extract Word Document
|
||||||
@ -300,15 +301,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
xml-file: build/extracted-doc/word/document.xml
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
- name: Run Demo
|
|
||||||
run: npm run ts-node -- ./demo/30-template-document.ts
|
|
||||||
- name: Extract Word Document
|
|
||||||
run: npm run extract
|
|
||||||
- name: Validate XML
|
|
||||||
uses: ChristophWurst/xmllint-action@v1
|
|
||||||
with:
|
|
||||||
xml-file: build/extracted-doc/word/document.xml
|
|
||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
|
||||||
- name: Run Demo
|
- name: Run Demo
|
||||||
run: npm run ts-node -- ./demo/31-tables.ts
|
run: npm run ts-node -- ./demo/31-tables.ts
|
||||||
- name: Extract Word Document
|
- name: Extract Word Document
|
||||||
@ -679,3 +671,129 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
xml-file: build/extracted-doc/word/document.xml
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/71-page-borders-2.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/72-word-wrap.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/73-comments.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/73-comments.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
# - name: Run Demo
|
||||||
|
# run: npm run ts-node -- ./demo/75-tab-stops.ts
|
||||||
|
# - name: Extract Word Document
|
||||||
|
# run: npm run extract
|
||||||
|
# - name: Validate XML
|
||||||
|
# uses: ChristophWurst/xmllint-action@v1
|
||||||
|
# with:
|
||||||
|
# xml-file: build/extracted-doc/word/document.xml
|
||||||
|
# xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/76-compatibility.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/77-side-by-side-tables.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/78-thai-distributed.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/79-table-from-data-source.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/80-thai-distributed.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/81-continuous-header.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/82-new-headers-new-section.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/83-setting-languages.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
- name: Run Demo
|
||||||
|
run: npm run ts-node -- ./demo/84-positional-tabs.ts
|
||||||
|
- name: Extract Word Document
|
||||||
|
run: npm run extract
|
||||||
|
- name: Validate XML
|
||||||
|
uses: ChristophWurst/xmllint-action@v1
|
||||||
|
with:
|
||||||
|
xml-file: build/extracted-doc/word/document.xml
|
||||||
|
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
||||||
|
4
.github/workflows/github-pages.yml
vendored
4
.github/workflows/github-pages.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
- name: Checkout Repo
|
- name: Checkout Repo
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Build 🔧
|
- name: Build 🔧
|
||||||
run: |
|
run: |
|
||||||
npm run typedoc
|
npm run typedoc
|
||||||
@ -30,7 +30,7 @@ jobs:
|
|||||||
- name: Checkout Repo 🛎️
|
- name: Checkout Repo 🛎️
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci --force
|
||||||
- name: Download Artifact
|
- name: Download Artifact
|
||||||
uses: actions/download-artifact@master
|
uses: actions/download-artifact@master
|
||||||
with:
|
with:
|
||||||
|
13
.mocharc.json
Normal file
13
.mocharc.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"diff": true,
|
||||||
|
"spec": "src/**/*.ts",
|
||||||
|
"extension": ["ts"],
|
||||||
|
"package": "./package.json",
|
||||||
|
"reporter": "spec",
|
||||||
|
"slow": "75",
|
||||||
|
"timeout": "2000",
|
||||||
|
"ui": "bdd",
|
||||||
|
"watch-files": ["src/**/*.ts"],
|
||||||
|
"watch-ignore": ["build", "demo"],
|
||||||
|
"require": ["mocha.env", "ts-node/register", "tsconfig-paths/register"]
|
||||||
|
}
|
@ -41,3 +41,6 @@ build-tests
|
|||||||
|
|
||||||
# docs
|
# docs
|
||||||
docs
|
docs
|
||||||
|
|
||||||
|
# src
|
||||||
|
src
|
||||||
|
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"check-coverage": true,
|
"check-coverage": true,
|
||||||
"lines": 99.32,
|
"statements": 99.87,
|
||||||
"functions": 99.11,
|
"branches": 98.21,
|
||||||
"branches": 96.27,
|
"functions": 100,
|
||||||
"statements": 99.32,
|
"lines": 99.86,
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
],
|
],
|
||||||
|
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["streetsidesoftware.code-spell-checker", "dbaeumer.vscode-eslint"]
|
||||||
|
}
|
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Run Demo",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeArgs": [
|
||||||
|
"-r",
|
||||||
|
"${workspaceFolder}/node_modules/ts-node/register",
|
||||||
|
"-r",
|
||||||
|
"${workspaceFolder}/node_modules/tsconfig-paths/register"
|
||||||
|
],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"program": "${workspaceFolder}/demo/85-template-document.ts"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
47
README.md
47
README.md
@ -1,9 +1,9 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="clippy the assistant" src="https://i.imgur.com/37uBGhO.gif">
|
<img src="./logo/logo-animate.svg" width="100%" height="300" alt="clippy the assistant">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
Easily generate .docx files with JS/TS. Works for Node and on the Browser.
|
Easily generate and modify .docx files with JS/TS. Works for Node and on the Browser.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -11,7 +11,6 @@
|
|||||||
[![NPM version][npm-image]][npm-url]
|
[![NPM version][npm-image]][npm-url]
|
||||||
[![Downloads per month][downloads-image]][downloads-url]
|
[![Downloads per month][downloads-image]][downloads-url]
|
||||||
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||||
[![Dependency Status][daviddm-image]][daviddm-url]
|
|
||||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||||
[![PRs Welcome][pr-image]][pr-url]
|
[![PRs Welcome][pr-image]][pr-url]
|
||||||
@ -27,21 +26,22 @@
|
|||||||
|
|
||||||
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
||||||
|
|
||||||
* https://codepen.io/dolanmiu/pen/RwNeObg
|
- https://codepen.io/dolanmiu/pen/RwNeObg
|
||||||
* https://jsfiddle.net/dolanmiu/onadx1gu/
|
- https://jsfiddle.net/dolanmiu/onadx1gu/
|
||||||
|
|
||||||
Here is an example of `docx` working in `Angular`:
|
Here are examples of `docx` working in `Angular`:
|
||||||
|
|
||||||
* https://stackblitz.com/edit/angular-docx
|
- https://stackblitz.com/edit/angular-docx
|
||||||
|
- https://stackblitz.com/edit/angular-wmd6k3
|
||||||
|
|
||||||
Here is an example of `docx` working in `React`:
|
Here are examples of `docx` working in `React`:
|
||||||
|
|
||||||
* https://stackblitz.com/edit/react-docx
|
- https://stackblitz.com/edit/react-docx
|
||||||
* https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
- https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||||
|
|
||||||
Here is an example of `docx` working in `Vue.js`:
|
Here is an example of `docx` working in `Vue.js`:
|
||||||
|
|
||||||
* https://stackblitz.com/edit/vuejs-docx
|
- https://stackblitz.com/edit/vuejs-docx
|
||||||
|
|
||||||
## Node
|
## Node
|
||||||
|
|
||||||
@ -49,15 +49,15 @@ Press `endpoint` on the `RunKit` website:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
* https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
|
- https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
|
||||||
* https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
|
- https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
|
||||||
* https://runkit.com/dolanmiu/docx-demo3 - Bullet points
|
- https://runkit.com/dolanmiu/docx-demo3 - Bullet points
|
||||||
* https://runkit.com/dolanmiu/docx-demo4 - Simple table
|
- https://runkit.com/dolanmiu/docx-demo4 - Simple table
|
||||||
* https://runkit.com/dolanmiu/docx-demo5 - Images
|
- https://runkit.com/dolanmiu/docx-demo5 - Images
|
||||||
* https://runkit.com/dolanmiu/docx-demo6 - Margins
|
- https://runkit.com/dolanmiu/docx-demo6 - Margins
|
||||||
* https://runkit.com/dolanmiu/docx-demo7 - Landscape
|
- https://runkit.com/dolanmiu/docx-demo7 - Landscape
|
||||||
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
- https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
||||||
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
- https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||||
|
|
||||||
More [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
More [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
|
|
||||||
@ -85,9 +85,10 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
|||||||
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
||||||
[<img src="https://i.imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
[<img src="https://i.imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
||||||
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
||||||
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing" />](https://www.arity.co/)
|
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing"/>](https://www.arity.co/)
|
||||||
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
|
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
|
||||||
|
[<img src="https://i.imgur.com/AKGhtlh.png" alt="drawing"/>](https://lexense.com/)
|
||||||
|
[<img src="https://i.imgur.com/9tqJaHw.png" alt="drawing" height="50"/>](https://novelpad.co/)
|
||||||
|
|
||||||
...and many more!
|
...and many more!
|
||||||
|
|
||||||
@ -104,8 +105,6 @@ Made with 💖
|
|||||||
[downloads-url]: https://npmjs.org/package/docx
|
[downloads-url]: https://npmjs.org/package/docx
|
||||||
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
||||||
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
|
||||||
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
|
||||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||||
[snky-url]: https://snyk.io/test/github/dolanmiu/docx
|
[snky-url]: https://snyk.io/test/github/dolanmiu/docx
|
||||||
[gitter-image]: https://badges.gitter.im/dolanmiu/docx.svg
|
[gitter-image]: https://badges.gitter.im/dolanmiu/docx.svg
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Simple example to add text to a document
|
// Simple example to add text to a document
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -14,9 +14,10 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "Foo Bar",
|
text: "Foo Bar",
|
||||||
bold: true,
|
bold: true,
|
||||||
|
size: 40,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Generate a CV
|
// Generate a CV
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, Tab, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||||
|
|
||||||
// tslint:disable:no-shadowed-variable
|
// tslint:disable:no-shadowed-variable
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ interface Skill {
|
|||||||
readonly name: string;
|
readonly name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Achivement {
|
interface Achievement {
|
||||||
readonly issuer: string;
|
readonly issuer: string;
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ const experiences: Experience[] = [
|
|||||||
{
|
{
|
||||||
isCurrent: false,
|
isCurrent: false,
|
||||||
summary:
|
summary:
|
||||||
"Full-stack developer working with Angular, Node and TypeScript. Working for the iShares platform. Emphasis on Dev-ops and developing the continous integration pipeline.",
|
"Full-stack developer working with Angular, Node and TypeScript. Working for the iShares platform. Emphasis on Dev-ops and developing the continuous integration pipeline.",
|
||||||
title: "Software Developer",
|
title: "Software Developer",
|
||||||
endDate: {
|
endDate: {
|
||||||
month: 11,
|
month: 11,
|
||||||
@ -98,6 +98,7 @@ const experiences: Experience[] = [
|
|||||||
{
|
{
|
||||||
isCurrent: false,
|
isCurrent: false,
|
||||||
summary:
|
summary:
|
||||||
|
// cspell:disable-next-line
|
||||||
"Develop web commerce platforms for various high profile clients.\n\nCreated a log analysis web application with the Play Framework in Java, incorporating Test Driven Development. It asynchronously uploads and processes large (2 GB) log files, and outputs meaningful results in context with the problem. \n\nAnalysis and development of the payment system infrastructure and user accounts section to be used by several clients of the company such as Waitrose, Tally Weijl, DJ Sports, Debenhams, Ann Summers, John Lewis and others.\n\nTechnologies used include WebSphere Commerce, Java, JavaScript and JSP.",
|
"Develop web commerce platforms for various high profile clients.\n\nCreated a log analysis web application with the Play Framework in Java, incorporating Test Driven Development. It asynchronously uploads and processes large (2 GB) log files, and outputs meaningful results in context with the problem. \n\nAnalysis and development of the payment system infrastructure and user accounts section to be used by several clients of the company such as Waitrose, Tally Weijl, DJ Sports, Debenhams, Ann Summers, John Lewis and others.\n\nTechnologies used include WebSphere Commerce, Java, JavaScript and JSP.",
|
||||||
title: "Java Developer",
|
title: "Java Developer",
|
||||||
endDate: {
|
endDate: {
|
||||||
@ -118,7 +119,7 @@ const education: Education[] = [
|
|||||||
{
|
{
|
||||||
degree: "Master of Science (MSc)",
|
degree: "Master of Science (MSc)",
|
||||||
fieldOfStudy: "Computer Science",
|
fieldOfStudy: "Computer Science",
|
||||||
notes: "Exam Results: 1st Class with Distinction, Dissertation: 1st Class with Distinction\n\nRelevant Courses: Java and C# Programming, Software Engineering, Artificial Intelligence, \nComputational Photography, Algorithmics, Architecture and Hardware.\n\nCreated a Windows 8 game in JavaScript for the dissertation. \n\nCreated an award-winning 3D stereoscopic game in C# using XNA.",
|
notes: "Exam Results: 1st Class with Distinction, Dissertation: 1st Class with Distinction\n\nRelevant Courses: Java and C# Programming, Software Engineering, Artificial Intelligence, \nComputational Photography, Algorithms, Architecture and Hardware.\n\nCreated a Windows 8 game in JavaScript for the dissertation. \n\nCreated an award-winning 3D stereoscopic game in C# using XNA.",
|
||||||
schoolName: "University College London",
|
schoolName: "University College London",
|
||||||
startDate: {
|
startDate: {
|
||||||
year: 2012,
|
year: 2012,
|
||||||
@ -156,7 +157,7 @@ const skills: Skill[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const achievements: Achivement[] = [
|
const achievements: Achievement[] = [
|
||||||
{
|
{
|
||||||
issuer: "Oracle",
|
issuer: "Oracle",
|
||||||
name: "Oracle Certified Expert",
|
name: "Oracle Certified Expert",
|
||||||
@ -165,7 +166,7 @@ const achievements: Achivement[] = [
|
|||||||
|
|
||||||
class DocumentCreator {
|
class DocumentCreator {
|
||||||
// tslint:disable-next-line: typedef
|
// tslint:disable-next-line: typedef
|
||||||
public create([experiences, educations, skills, achivements]: [Experience[], Education[], Skill[], Achivement[]]): Document {
|
public create([experiences, educations, skills, achievements]: [Experience[], Education[], Skill[], Achievement[]]): Document {
|
||||||
const document = new Document({
|
const document = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
@ -221,7 +222,7 @@ class DocumentCreator {
|
|||||||
this.createSubHeading("Skills"),
|
this.createSubHeading("Skills"),
|
||||||
this.createSkillList(skills),
|
this.createSkillList(skills),
|
||||||
this.createSubHeading("Achievements"),
|
this.createSubHeading("Achievements"),
|
||||||
...this.createAchivementsList(achivements),
|
...this.createAchievementsList(achievements),
|
||||||
this.createSubHeading("Interests"),
|
this.createSubHeading("Interests"),
|
||||||
this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."),
|
this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."),
|
||||||
this.createHeading("References"),
|
this.createHeading("References"),
|
||||||
@ -283,7 +284,7 @@ class DocumentCreator {
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: `\t${dateText}`,
|
children: [new Tab(), dateText],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@ -318,8 +319,8 @@ class DocumentCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
public createAchivementsList(achivements: any[]): Paragraph[] {
|
public createAchievementsList(achievements: any[]): Paragraph[] {
|
||||||
return achivements.map(
|
return achievements.map(
|
||||||
(achievement) =>
|
(achievement) =>
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: achievement.name,
|
text: achievement.name,
|
||||||
|
@ -52,18 +52,20 @@ const table = new Table({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
numbering:{
|
numbering: {
|
||||||
config:[{
|
config: [
|
||||||
reference: 'ref1',
|
|
||||||
levels: [
|
|
||||||
{
|
{
|
||||||
level: 0,
|
reference: "ref1",
|
||||||
format: LevelFormat.DECIMAL,
|
levels: [
|
||||||
text: '%1)',
|
{
|
||||||
start: 50,
|
level: 0,
|
||||||
}
|
format: LevelFormat.DECIMAL,
|
||||||
],
|
text: "%1)",
|
||||||
}]
|
start: 50,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
default: {
|
default: {
|
||||||
@ -184,11 +186,11 @@ const doc = new Document({
|
|||||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
rightTabStop: TabStopPosition.MAX,
|
rightTabStop: TabStopPosition.MAX,
|
||||||
leftTabStop: 453.543307087,
|
leftTabStop: 453.543307087,
|
||||||
numbering : {
|
numbering: {
|
||||||
reference: 'ref1',
|
reference: "ref1",
|
||||||
instance: 0,
|
instance: 0,
|
||||||
level: 0,
|
level: 0,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -18,10 +18,15 @@ const doc = new Document({
|
|||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: ["Hello", new FootnoteReferenceRun(1)],
|
children: ["Hello"],
|
||||||
}),
|
}),
|
||||||
|
new FootnoteReferenceRun(1),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: [" World!", new FootnoteReferenceRun(2)],
|
children: [" World!"],
|
||||||
|
}),
|
||||||
|
new FootnoteReferenceRun(2),
|
||||||
|
new TextRun({
|
||||||
|
children: [" GitHub!"],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -35,15 +40,17 @@ const doc = new Document({
|
|||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: ["Hello", new FootnoteReferenceRun(4)],
|
children: ["Hello"],
|
||||||
}),
|
}),
|
||||||
|
new FootnoteReferenceRun(4),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
children: [" World!", new FootnoteReferenceRun(5)],
|
children: [" World!"],
|
||||||
}),
|
}),
|
||||||
|
new FootnoteReferenceRun(5),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
|
children: [new TextRun("Hello World Again"), new FootnoteReferenceRun(6)],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Export to base64 string - Useful in a browser environment.
|
// Export to base64 string - Useful in a browser environment.
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -15,7 +15,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tBar",
|
children: [new Tab(), "Bar"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Example on how to customise the look at feel using Styles
|
// Example on how to customize the look at feel using Styles
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {
|
import {
|
||||||
@ -82,6 +82,32 @@ const doc = new Document({
|
|||||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
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: {
|
numbering: {
|
||||||
@ -169,6 +195,14 @@ const doc = new Document({
|
|||||||
new TextRun({
|
new TextRun({
|
||||||
text: "and back to normal.",
|
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({
|
new Paragraph({
|
||||||
@ -182,6 +216,49 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
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",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun, PageReference } from "../build";
|
import {
|
||||||
|
Bookmark,
|
||||||
|
Document,
|
||||||
|
Footer,
|
||||||
|
HeadingLevel,
|
||||||
|
InternalHyperlink,
|
||||||
|
Packer,
|
||||||
|
PageBreak,
|
||||||
|
Paragraph,
|
||||||
|
TextRun,
|
||||||
|
PageReference,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
const LOREM_IPSUM =
|
const LOREM_IPSUM =
|
||||||
|
/* cspell:disable-next-line */
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Creates two paragraphs, one with a border and one without
|
// Creates two paragraphs, one with a border and one without
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { BorderStyle, Document, Packer, Paragraph } from "../build";
|
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -25,6 +25,36 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "",
|
||||||
|
border: {
|
||||||
|
top: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "This will ",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "have a border.",
|
||||||
|
border: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " This will not.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Numbering and bullet points example
|
// Numbering and bullet points example
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
import { AlignmentType, convertInchesToTwip, Document, Footer, Header, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
numbering: {
|
numbering: {
|
||||||
@ -119,6 +119,46 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hey you",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "What's up fam",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hey you",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "What's up fam",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Hey you",
|
text: "Hey you",
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
// Example on how to use a template document
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, ImportDotx, Packer, Paragraph } from "../build";
|
|
||||||
|
|
||||||
const importDotx = new ImportDotx();
|
|
||||||
const filePath = "./demo/dotx/template.dotx";
|
|
||||||
|
|
||||||
fs.readFile(filePath, (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
throw new Error(`Failed to read file ${filePath}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
importDotx.extract(data).then((templateDocument) => {
|
|
||||||
const doc = new Document(
|
|
||||||
{
|
|
||||||
sections: [
|
|
||||||
{
|
|
||||||
properties: {
|
|
||||||
titlePage: templateDocument.titlePageIsDefined,
|
|
||||||
},
|
|
||||||
children: [new Paragraph("Hello World")],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
template: templateDocument,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -34,8 +34,7 @@ const doc = new Document({
|
|||||||
new TableCell({
|
new TableCell({
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text:
|
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",
|
||||||
"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,
|
heading: HeadingLevel.HEADING_1,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
// Add image to table cell
|
// Add image to table cell
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||||
|
|
||||||
|
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4jHR4hHh4hHx8hHyAiHyAjHyAjHSAjHR4jHR4hHh4hHx8hHyAjHyAjHyAjHSAjHR4hHR4hHR4hHx8iHyAjHyAjHyAjHSAhHR4hHR4hHR4hHx8jHyAjHyAjHyAjHyC9S2xeAAAA7nRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFxgZGhscHR4fICEiIyQlJicoKSorLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZISUpLTE1OUFFSU1RVVllaW1xdXmBhYmNkZWZnaGprbG1ub3Byc3R1dnd4eXp8fn+AgYKDhIWGiImKi4yNj5CRkpOUlZaXmJmam5ydnp+goaKjpKaoqqusra6vsLGys7S1tri5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+fkZpVQAABcBJREFUGBntwftjlQMcBvDnnLNL22qzJjWlKLHFVogyty3SiFq6EZliqZGyhnSxsLlMRahYoZKRFcul5dKFCatYqWZaNKvWtrPz/A2+7/b27qRzec/lPfvl/XxgMplMJpPJZDKZAtA9HJ3ppnIez0KnSdtC0RCNznHdJrbrh85wdSlVVRaEXuoGamYi5K5430HNiTiEWHKJg05eRWgNfKeV7RxbqUhGKPV/207VupQ8is0IoX5vtFC18SqEHaK4GyHTZ2kzVR8PBTCO4oANIZL4ShNVZcOhKKeYg9DoWdhI1ec3os2VFI0JCIUez5+i6st0qJZRrEAIJCw+QdW223BG/EmKwTBc/IJ/qfp2FDrkUnwFo8U9dZyqnaPhxLqfYjyM1S3vb6p+GGOBszsojoTDSDFz6qj66R4LzvYJxVMwUNRjf1H1ywQr/megg2RzLximy8waqvbda8M5iijegVEiHjlM1W/3h+FcXesphsMY4dMOUnUgOxyuPEzxPQwRNvV3qg5Nj4BreyimwADWe/dRVTMjEm6MoGLzGwtystL6RyOY3qSqdlYU3FpLZw1VW0sK5943MvUCKwJ1noNtjs6Ohge76Zq9ZkfpigU5WWkDYuCfbs1U5HWFR8/Qq4a9W0uK5k4ZmdrTCl8spGIePLPlbqqsc1Afe83O0hULc8alDYiBd7ZyitYMeBfR55rR2fOKP6ioPk2dGvZ+UVI0d8rtqT2tcCexlqK2F3wRn5Q+YVbBqrLKOupkr9lZujAOrmS0UpTb4JeIPkNHZ+cXr6uoPk2vyuBSPhWLEKj45PQJuQWryyqP0Z14uGLdROHIRNBEXDR09EP5r62rOHCazhrD4VKPwxTH+sIA3ZPTJ+YuWV22n+IruHFDC8X2CBjnPoolcGc2FYUwzmsUWXDHsoGKLBhmN0VvuBVfTVE/AAbpaid5CB4MbaLY1QXGuIViLTyZQcVyGGMuxWPwaA0Vk2GI9RRp8Ci2iuLkIBjhT5LNUfAspZFiTwyC72KK7+DNg1SsRvCNp3gZXq2k4iEEXSHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
|
width: {
|
||||||
|
size: 8640,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
@ -17,7 +23,19 @@ const table = new Table({
|
|||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: Buffer.from(imageBase64Data, "base64"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -27,7 +45,19 @@ const table = new Table({
|
|||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [],
|
children: [],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Example of making content of section vertically aligned
|
// Example of making content of section vertically aligned
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun } from "../build";
|
import { Document, Packer, Paragraph, VerticalAlign, TextRun, Tab } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -18,7 +18,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -123,8 +123,7 @@ const noBorderTable = new Table({
|
|||||||
new TableCell({
|
new TableCell({
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text:
|
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",
|
||||||
"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,
|
heading: HeadingLevel.HEADING_1,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -25,6 +25,11 @@ const doc = new Document({
|
|||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
},
|
},
|
||||||
|
altText: {
|
||||||
|
title: "This is an ultimate title",
|
||||||
|
description: "This is an ultimate image",
|
||||||
|
name: "My Ultimate Image",
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -43,8 +43,7 @@ const doc = new Document({
|
|||||||
style: "strong",
|
style: "strong",
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text:
|
text: " - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||||
" - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
MathSubScript,
|
MathSubScript,
|
||||||
MathSubSuperScript,
|
MathSubSuperScript,
|
||||||
MathSum,
|
MathSum,
|
||||||
|
MathIntegral,
|
||||||
MathSuperScript,
|
MathSuperScript,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
@ -90,6 +91,35 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathIntegral({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new Math({
|
new Math({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Change background colour of whole document
|
// Change background colour of whole document
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
background: {
|
background: {
|
||||||
@ -19,7 +19,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Example of how to change page borders
|
// Example of how to change page borders
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
import { Document, HeadingLevel, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [
|
sections: [
|
||||||
@ -25,7 +25,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
PageNumber,
|
PageNumber,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
ShadingType,
|
ShadingType,
|
||||||
|
Tab,
|
||||||
TextRun,
|
TextRun,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
|
|
||||||
@ -111,7 +112,17 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
bold: true,
|
bold: true,
|
||||||
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
children: [new Tab(), "use Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
bold: true,
|
||||||
|
text: "And some style changes",
|
||||||
|
revision: {
|
||||||
|
id: 4,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
bold: false,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
HorizontalPositionAlign,
|
HorizontalPositionAlign,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
|
Tab,
|
||||||
TextRun,
|
TextRun,
|
||||||
VerticalPositionAlign,
|
VerticalPositionAlign,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
@ -67,7 +68,7 @@ const doc = new Document({
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new TextRun({
|
new TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -4,7 +4,7 @@ import * as fs from "fs";
|
|||||||
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "../build";
|
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
creator: 'Me',
|
creator: "Me",
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
properties: {},
|
properties: {},
|
||||||
|
@ -13,11 +13,13 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({ children: [
|
new Paragraph({
|
||||||
new TextRun('This text will be in the first column.'),
|
children: [
|
||||||
new ColumnBreak(),
|
new TextRun("This text will be in the first column."),
|
||||||
new TextRun('This text will be in the second column.'),
|
new ColumnBreak(),
|
||||||
] }),
|
new TextRun("This text will be in the second column."),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
63
demo/71-page-borders-2.ts
Normal file
63
demo/71-page-borders-2.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Example demonstrating page borders with style, colors and size
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, TextRun, Paragraph, BorderStyle, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
borders: {
|
||||||
|
pageBorderBottom: {
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 2 * 8, //2pt;
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
pageBorderLeft: {
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 1 * 8, //1pt;
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
pageBorderRight: {
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 1 * 8, //1pt;
|
||||||
|
color: "FF00AA",
|
||||||
|
},
|
||||||
|
pageBorderTop: {
|
||||||
|
style: BorderStyle.SINGLE,
|
||||||
|
size: 1 * 8, //1pt;
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
pageBorders: {
|
||||||
|
display: PageBorderDisplay.ALL_PAGES,
|
||||||
|
offsetFrom: PageBorderOffsetFrom.TEXT,
|
||||||
|
zOrder: PageBorderZOrder.FRONT,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Used to export the file into a .docx file
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
55
demo/72-word-wrap.ts
Normal file
55
demo/72-word-wrap.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Example on how to preserve word wrap text. Works with all languages.
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun, SpaceType } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
wordWrap: true,
|
||||||
|
children: [
|
||||||
|
new TextRun("我今天遛狗去公园"),
|
||||||
|
new TextRun({
|
||||||
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
wordWrap: true,
|
||||||
|
children: [
|
||||||
|
new TextRun(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
||||||
|
),
|
||||||
|
new TextRun({
|
||||||
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("我今天遛狗去公园"),
|
||||||
|
new TextRun({
|
||||||
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
|
||||||
|
),
|
||||||
|
new TextRun({
|
||||||
|
text: "456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345456435234523456435564745673456345",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
138
demo/73-comments.ts
Normal file
138
demo/73-comments.ts
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
// Simple example to add comments to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEnd, CommentReference } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
comments: {
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
author: "Ray Chen",
|
||||||
|
date: new Date(),
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "some initial text content",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "comment text content",
|
||||||
|
}),
|
||||||
|
new TextRun({ text: "", break: 1 }),
|
||||||
|
new TextRun({
|
||||||
|
text: "More text here",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
author: "Bob Ross",
|
||||||
|
date: new Date(),
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Some initial text content",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "comment text content",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
author: "John Doe",
|
||||||
|
date: new Date(),
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Hello World",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
author: "Beatriz",
|
||||||
|
date: new Date(),
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Another reply",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new CommentRangeStart(0),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new CommentRangeEnd(0),
|
||||||
|
new TextRun({
|
||||||
|
children: [new CommentReference(0)],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new CommentRangeStart(1),
|
||||||
|
new CommentRangeStart(2),
|
||||||
|
new CommentRangeStart(3),
|
||||||
|
new TextRun({
|
||||||
|
text: "Some text which need commenting",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new CommentRangeEnd(1),
|
||||||
|
new TextRun({
|
||||||
|
children: [new CommentReference(1)],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new CommentRangeEnd(2),
|
||||||
|
new TextRun({
|
||||||
|
children: [new CommentReference(2)],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new CommentRangeEnd(3),
|
||||||
|
new TextRun({
|
||||||
|
children: [new CommentReference(3)],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
30
demo/74-nodejs-stream.ts
Normal file
30
demo/74-nodejs-stream.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Exporting the document as a stream
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [new Tab(), "Github is the best"],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stream = Packer.toStream(doc);
|
||||||
|
stream.pipe(fs.createWriteStream("My Document.docx"));
|
80
demo/75-tab-stops.ts
Normal file
80
demo/75-tab-stops.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Example of using tab stops
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||||
|
|
||||||
|
const columnWidth = TabStopPosition.MAX / 4;
|
||||||
|
const receiptTabStops = [
|
||||||
|
// no need to define first left tab column
|
||||||
|
// the right aligned tab column position should point to the end of column
|
||||||
|
// i.e. in this case
|
||||||
|
// (end position of 1st) + (end position of current)
|
||||||
|
// columnWidth + columnWidth = columnWidth * 2
|
||||||
|
|
||||||
|
{ type: TabStopType.RIGHT, position: columnWidth * 2 },
|
||||||
|
{ type: TabStopType.RIGHT, position: columnWidth * 3 },
|
||||||
|
{ type: TabStopType.RIGHT, position: TabStopPosition.MAX },
|
||||||
|
],
|
||||||
|
twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
children: [new TextRun("Receipt 001")],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: twoTabStops,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "To Bob.\tBy Alice.",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: twoTabStops,
|
||||||
|
children: [new TextRun("Foo Inc\tBar Inc")],
|
||||||
|
}),
|
||||||
|
new Paragraph({ text: "" }),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Item\tPrice\tQuantity\tSub-total",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
text: "Item 3\t10\t5\t50",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
tabStops: receiptTabStops,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "\t\t\tTotal: 200",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stream = Packer.toStream(doc);
|
||||||
|
stream.pipe(fs.createWriteStream("My Document.docx"));
|
87
demo/76-compatibility.ts
Normal file
87
demo/76-compatibility.ts
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// Add compatibility options
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
compatibility: {
|
||||||
|
useSingleBorderforContiguousCells: true,
|
||||||
|
wordPerfectJustification: true,
|
||||||
|
noTabStopForHangingIndent: true,
|
||||||
|
noLeading: true,
|
||||||
|
spaceForUnderline: true,
|
||||||
|
noColumnBalance: true,
|
||||||
|
balanceSingleByteDoubleByteWidth: true,
|
||||||
|
noExtraLineSpacing: true,
|
||||||
|
doNotLeaveBackslashAlone: true,
|
||||||
|
underlineTrailingSpaces: true,
|
||||||
|
doNotExpandShiftReturn: true,
|
||||||
|
spacingInWholePoints: true,
|
||||||
|
lineWrapLikeWord6: true,
|
||||||
|
printBodyTextBeforeHeader: true,
|
||||||
|
printColorsBlack: true,
|
||||||
|
spaceWidth: true,
|
||||||
|
showBreaksInFrames: true,
|
||||||
|
subFontBySize: true,
|
||||||
|
suppressBottomSpacing: true,
|
||||||
|
suppressTopSpacing: true,
|
||||||
|
suppressSpacingAtTopOfPage: true,
|
||||||
|
suppressTopSpacingWP: true,
|
||||||
|
suppressSpBfAfterPgBrk: true,
|
||||||
|
swapBordersFacingPages: true,
|
||||||
|
convertMailMergeEsc: true,
|
||||||
|
truncateFontHeightsLikeWP6: true,
|
||||||
|
macWordSmallCaps: true,
|
||||||
|
usePrinterMetrics: true,
|
||||||
|
doNotSuppressParagraphBorders: true,
|
||||||
|
wrapTrailSpaces: true,
|
||||||
|
footnoteLayoutLikeWW8: true,
|
||||||
|
shapeLayoutLikeWW8: true,
|
||||||
|
alignTablesRowByRow: true,
|
||||||
|
forgetLastTabAlignment: true,
|
||||||
|
adjustLineHeightInTable: true,
|
||||||
|
autoSpaceLikeWord95: true,
|
||||||
|
noSpaceRaiseLower: true,
|
||||||
|
doNotUseHTMLParagraphAutoSpacing: true,
|
||||||
|
layoutRawTableWidth: true,
|
||||||
|
layoutTableRowsApart: true,
|
||||||
|
useWord97LineBreakRules: true,
|
||||||
|
doNotBreakWrappedTables: true,
|
||||||
|
doNotSnapToGridInCell: true,
|
||||||
|
selectFieldWithFirstOrLastCharacter: true,
|
||||||
|
applyBreakingRules: true,
|
||||||
|
doNotWrapTextWithPunctuation: true,
|
||||||
|
doNotUseEastAsianBreakRules: true,
|
||||||
|
useWord2002TableStyleRules: true,
|
||||||
|
growAutofit: true,
|
||||||
|
useFELayout: true,
|
||||||
|
useNormalStyleForList: true,
|
||||||
|
doNotUseIndentAsNumberingTabStop: true,
|
||||||
|
useAlternateEastAsianLineBreakRules: true,
|
||||||
|
allowSpaceOfSameStyleInTable: true,
|
||||||
|
doNotSuppressIndentation: true,
|
||||||
|
doNotAutofitConstrainedTables: true,
|
||||||
|
autofitToFirstFixedWidthCell: true,
|
||||||
|
underlineTabInNumberingList: true,
|
||||||
|
displayHangulFixedWidth: true,
|
||||||
|
splitPgBreakAndParaMark: true,
|
||||||
|
doNotVerticallyAlignCellWithSp: true,
|
||||||
|
doNotBreakConstrainedForcedTable: true,
|
||||||
|
ignoreVerticalAlignmentInTextboxes: true,
|
||||||
|
useAnsiKerningPairs: true,
|
||||||
|
cachedColumnBalance: true,
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
116
demo/77-side-by-side-tables.ts
Normal file
116
demo/77-side-by-side-tables.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
// Exporting the document as a stream
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, WidthType } from "../build";
|
||||||
|
|
||||||
|
const table1 = new Table({
|
||||||
|
columnWidths: [3505, 5505],
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table2 = new Table({
|
||||||
|
columnWidths: [3505, 5505],
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Foo")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Bar")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const noBorderTable = new Table({
|
||||||
|
borders: TableBorders.NONE,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [table1],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [table2],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [noBorderTable],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const stream = Packer.toStream(doc);
|
||||||
|
stream.pipe(fs.createWriteStream("My Document.docx"));
|
27
demo/78-thai-distributed.ts
Normal file
27
demo/78-thai-distributed.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัท บิสกิด จำกัด (บริษัทฯ) ได้จดทะเบียนจัดตั้งขึ้นเป็นบริษัทจำกัดตามประมวลกฎหมายแพ่งและพาณิชย์ของประเทศไทย เมื่อวันที่ 30 พฤษภาคม 2561 ทะเบียนนิติบุคคลเลขที่ 0845561005665",
|
||||||
|
size: 36,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
193
demo/79-table-from-data-source.ts
Normal file
193
demo/79-table-from-data-source.ts
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
// Example of how you would create a table and add data to it from a data source
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
VerticalAlign,
|
||||||
|
TextDirection,
|
||||||
|
TextRun,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
interface StockPrice {
|
||||||
|
readonly date: Date;
|
||||||
|
readonly ticker: string;
|
||||||
|
readonly price: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DATA: StockPrice[] = [
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-28"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-29"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.15,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-30"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.46,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-08-31"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.78,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-04"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 20.59,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-05"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.54,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-06"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.29,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-07"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 18.82,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-10"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.53,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-11"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.36,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-12"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.55,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-13"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-14"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.83,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date("2007-09-17"),
|
||||||
|
ticker: "Apple",
|
||||||
|
price: 19.77,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const generateRows = (prices: StockPrice[]): TableRow[] =>
|
||||||
|
prices.map(
|
||||||
|
({ date, ticker, price }) =>
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(date.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(ticker)],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(price.toString())],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
|
width: {
|
||||||
|
size: 9070,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Date",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Ticker",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.LEFT_TO_RIGHT_TOP_TO_BOTTOM,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Price",
|
||||||
|
bold: true,
|
||||||
|
size: 40,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
...generateRows(DATA),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
49
demo/80-thai-distributed.ts
Normal file
49
demo/80-thai-distributed.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "test",
|
||||||
|
name: "Test",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertMillimetersToTwip(6.4) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
|
top: 0,
|
||||||
|
right: convertMillimetersToTwip(24),
|
||||||
|
bottom: convertMillimetersToTwip(24),
|
||||||
|
left: convertMillimetersToTwip(24),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.THAI_DISTRIBUTE,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "บริษัทฯ มีเงินสด 41,985.00 บาท และ 25,855.66 บาทตามลำดับ เงินสดทั้งจำนวนอยู่ในความดูแลและรับผิดชอบของกรรมการ บริษัทฯบันทึกการรับชำระเงินและการจ่ายชำระเงินผ่านบัญชีเงินสดเพียงเท่านั้น ซึ่งอาจกระทบต่อความถูกต้องครบถ้วนของการบันทึกบัญชี ทั้งนี้ขึ้นอยู่กับระบบการควบคุมภายในของบริษัท",
|
||||||
|
size: 28,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
148
demo/81-continuous-header.ts
Normal file
148
demo/81-continuous-header.ts
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// Example of a continuous header
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Creator",
|
||||||
|
title: "Title",
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: { titlePage: true },
|
||||||
|
headers: {
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
first: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
after: 500,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The first section ends after this paragraph.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.CONTINUOUS,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
148
demo/82-new-headers-new-section.ts
Normal file
148
demo/82-new-headers-new-section.ts
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
// Example of using headers and footers in a new section
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Creator",
|
||||||
|
title: "Title",
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE ONE",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
after: 500,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The first section ends after this paragraph.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "HEADER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "FOOTER PAGE TWO AND FOLLOWING PAGES",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac suscipit orci, in lobortis risus. Nulla vehicula rutrum finibus. Nullam consequat, magna in vehicula commodo, enim massa consectetur nisl, sit amet rutrum nunc ante vel lorem. Sed sit amet scelerisque velit. Proin non quam eget mauris aliquet posuere a sed orci. Proin posuere ante suscipit neque dignissim hendrerit. Pellentesque eget dapibus metus. Donec at mollis mauris. Vestibulum sit amet scelerisque nulla. Vivamus ipsum erat, tempor sed volutpat non, molestie at odio. Vivamus lectus ligula, finibus at mattis vitae, euismod sed tellus. Etiam neque massa, faucibus a fringilla nec, mollis at ex. Aliquam eget nibh tortor. Sed ut viverra libero. Nulla facilisis bibendum quam eget porttitor.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed eget nunc ac turpis facilisis volutpat. Duis eget arcu vitae neque porta hendrerit. Proin vel ante nulla. Duis congue efficitur dui. Suspendisse potenti. Aliquam aliquam nibh eu ipsum sagittis efficitur. Quisque sagittis metus dui, vitae suscipit tortor sollicitudin at. Suspendisse convallis, sem ac ornare condimentum, odio ipsum dapibus justo, a aliquam risus massa ut enim. Mauris vel placerat nibh. Ut iaculis vitae nibh at elementum. Quisque hendrerit et magna vitae mollis. Duis dictum euismod leo, at cursus risus sodales sed.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Sed gravida commodo felis, at aliquet risus volutpat ut. Nam nec ex eleifend tellus sodales volutpat nec ac nibh. Vestibulum pretium, leo vitae lobortis accumsan, urna libero euismod ante, consequat aliquam enim risus id nisl. Donec sagittis, justo eu luctus posuere, leo purus pellentesque turpis, eget volutpat mi leo vitae lacus. Etiam ante ante, posuere at augue non, lacinia ornare purus. Praesent vitae velit in enim congue maximus. Vivamus tincidunt fringilla neque. Curabitur fermentum justo nec sapien porttitor, ac ullamcorper nisi imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed non orci vel eros egestas eleifend sit amet a diam. Duis mattis at ligula quis faucibus. Donec elementum lacus velit, a vehicula nunc gravida a. Phasellus eget nunc vehicula, varius velit a, maximus velit. Sed a suscipit nisi, non hendrerit felis. Proin mattis facilisis massa, quis elementum neque fringilla non.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "The second section starts with the headline above. Move cursor to the end of this text and press enter until next page is generated in continuous section break mode.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
69
demo/83-setting-languages.ts
Normal file
69
demo/83-setting-languages.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Simple example to add text to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
default: {
|
||||||
|
document: {
|
||||||
|
run: {
|
||||||
|
color: "ff0000",
|
||||||
|
language: {
|
||||||
|
value: "es-ES",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "frenchNormal",
|
||||||
|
name: "French Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "999999",
|
||||||
|
italics: true,
|
||||||
|
language: {
|
||||||
|
value: "fr-FR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "koreanNormal",
|
||||||
|
name: "Korean Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "0000ff",
|
||||||
|
bold: true,
|
||||||
|
language: {
|
||||||
|
value: "ko-KR",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Yo vivo en Granada, una ciudad pequeña que tiene monumentos muy importantes como la Alhambra. Aquí la comida es deliciosa y son famosos el gazpacho, el rebujito y el salmorejo.",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Toute personne a droit à l'éducation. L'éducation doit être gratuite, au moins en ce qui concerne l'enseignement élémentaire et fondamental. L'enseignement élémentaire est obligatoire. L'enseignement technique et professionnel doit être généralisé; l'accès aux études supérieures doit être ouvert en pleine égalité à tous en fonction de leur mérite.",
|
||||||
|
style: "frenchNormal",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "대법관은 대법원장의 제청으로 국회의 동의를 얻어 대통령이 임명한다. 강화조약. 국가는 국민 모두의 생산 및 생활의 기반이 되는 국토의 효율적이고 균형있는 이용·개발과 보전을 위하여 법률이 정하는 바에 의하여 그에 관한 필요한 제한과 의무를 과할 수 있다, 국가는 청원에 대하여 심사할 의무를 진다.",
|
||||||
|
style: "koreanNormal",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
60
demo/84-positional-tabs.ts
Normal file
60
demo/84-positional-tabs.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Simple example apply positional tabs to a document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
PositionalTab,
|
||||||
|
Tab,
|
||||||
|
TextRun,
|
||||||
|
PositionalTabAlignment,
|
||||||
|
PositionalTabRelativeTo,
|
||||||
|
PositionalTabLeader,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Full name"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.RIGHT,
|
||||||
|
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||||
|
leader: PositionalTabLeader.DOT,
|
||||||
|
}),
|
||||||
|
"John Doe",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.CENTER,
|
||||||
|
relativeTo: PositionalTabRelativeTo.INDENT,
|
||||||
|
leader: PositionalTabLeader.HYPHEN,
|
||||||
|
}),
|
||||||
|
"Foo bar",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
155
demo/85-template-document.ts
Normal file
155
demo/85-template-document.ts
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// Patch a document with patches
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
ExternalHyperlink,
|
||||||
|
HeadingLevel,
|
||||||
|
ImageRun,
|
||||||
|
Paragraph,
|
||||||
|
patchDocument,
|
||||||
|
PatchType,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
TextDirection,
|
||||||
|
TextRun,
|
||||||
|
VerticalAlign,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
|
||||||
|
patches: {
|
||||||
|
name: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Sir. "), new TextRun("John Doe"), new TextRun("(The Conqueror)")],
|
||||||
|
},
|
||||||
|
table_heading_1: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Heading wow!")],
|
||||||
|
},
|
||||||
|
item_1: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [
|
||||||
|
new TextRun("#657"),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "BBC News Link",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
link: "https://www.bbc.co.uk/news",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
paragraph_replace: {
|
||||||
|
type: PatchType.DOCUMENT,
|
||||||
|
children: [
|
||||||
|
new Paragraph("Lorem ipsum paragraph"),
|
||||||
|
new Paragraph("Another paragraph"),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a "),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Google Link",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
link: "https://www.google.co.uk",
|
||||||
|
}),
|
||||||
|
new ImageRun({ data: fs.readFileSync("./demo/images/dog.png"), transformation: { width: 100, height: 100 } }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
header_adjective: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Delightful Header")],
|
||||||
|
},
|
||||||
|
footer_text: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [
|
||||||
|
new TextRun("replaced just as"),
|
||||||
|
new TextRun(" well"),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "BBC News Link",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
link: "https://www.bbc.co.uk/news",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
image_test: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new ImageRun({ data: fs.readFileSync("./demo/images/image1.jpeg"), transformation: { width: 100, height: 100 } })],
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
type: PatchType.DOCUMENT,
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
|
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).then((doc) => {
|
||||||
|
fs.writeFileSync("My Document.docx", doc);
|
||||||
|
});
|
20
demo/86-generate-template.ts
Normal file
20
demo/86-generate-template.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Generate a template document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("{{template}}")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
15
demo/87-template-document.ts
Normal file
15
demo/87-template-document.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Patch a document with patches
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { patchDocument, PatchType, TextRun } from "../build";
|
||||||
|
|
||||||
|
patchDocument(fs.readFileSync("demo/assets/simple-template-2.docx"), {
|
||||||
|
patches: {
|
||||||
|
name: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Max")],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).then((doc) => {
|
||||||
|
fs.writeFileSync("My Document.docx", doc);
|
||||||
|
});
|
31
demo/88-template-document.ts
Normal file
31
demo/88-template-document.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Patch a document with patches
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
|
||||||
|
|
||||||
|
export const font = "Trebuchet MS";
|
||||||
|
export const getPatches = (fields: { [key: string]: string }) => {
|
||||||
|
const patches: { [key: string]: IPatch } = {};
|
||||||
|
|
||||||
|
for (const field in fields) {
|
||||||
|
patches[field] = {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun({ text: fields[field], font })],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return patches;
|
||||||
|
};
|
||||||
|
|
||||||
|
const patches = getPatches({
|
||||||
|
name: "Mr",
|
||||||
|
table_heading_1: "John",
|
||||||
|
item_1: "Doe",
|
||||||
|
paragraph_replace: "Lorem ipsum paragraph",
|
||||||
|
});
|
||||||
|
|
||||||
|
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
|
||||||
|
patches,
|
||||||
|
}).then((doc) => {
|
||||||
|
fs.writeFileSync("My Document.docx", doc);
|
||||||
|
});
|
29
demo/89-template-document.ts
Normal file
29
demo/89-template-document.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Patch a document with patches
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
|
||||||
|
|
||||||
|
export const font = "Trebuchet MS";
|
||||||
|
export const getPatches = (fields: { [key: string]: string }) => {
|
||||||
|
const patches: { [key: string]: IPatch } = {};
|
||||||
|
|
||||||
|
for (const field in fields) {
|
||||||
|
patches[field] = {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun({ text: fields[field], font })],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return patches;
|
||||||
|
};
|
||||||
|
|
||||||
|
const patches = getPatches({
|
||||||
|
salutation: "Mr.",
|
||||||
|
"first-name": "John",
|
||||||
|
});
|
||||||
|
|
||||||
|
patchDocument(fs.readFileSync("demo/assets/simple-template-3.docx"), {
|
||||||
|
patches,
|
||||||
|
}).then((doc) => {
|
||||||
|
fs.writeFileSync("My Document.docx", doc);
|
||||||
|
});
|
BIN
demo/assets/generated-template.docx
Normal file
BIN
demo/assets/generated-template.docx
Normal file
Binary file not shown.
BIN
demo/assets/simple-template-2.docx
Normal file
BIN
demo/assets/simple-template-2.docx
Normal file
Binary file not shown.
BIN
demo/assets/simple-template-3.docx
Normal file
BIN
demo/assets/simple-template-3.docx
Normal file
Binary file not shown.
BIN
demo/assets/simple-template.docx
Normal file
BIN
demo/assets/simple-template.docx
Normal file
Binary file not shown.
@ -24,7 +24,7 @@
|
|||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
new docx.TextRun({
|
new docx.TextRun({
|
||||||
text: "\tGithub is the best",
|
children: [new docx.Tab(), "Github is the best"],
|
||||||
bold: true,
|
bold: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -27,24 +27,26 @@ import { Document, Packer, Paragraph, TextRun } from "docx";
|
|||||||
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
||||||
// This simple example will only contain one section
|
// This simple example will only contain one section
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [{
|
sections: [
|
||||||
properties: {},
|
{
|
||||||
children: [
|
properties: {},
|
||||||
new Paragraph({
|
children: [
|
||||||
children: [
|
new Paragraph({
|
||||||
new TextRun("Hello World"),
|
children: [
|
||||||
new TextRun({
|
new TextRun("Hello World"),
|
||||||
text: "Foo Bar",
|
new TextRun({
|
||||||
bold: true,
|
text: "Foo Bar",
|
||||||
}),
|
bold: true,
|
||||||
new TextRun({
|
}),
|
||||||
text: "\tGithub is the best",
|
new TextRun({
|
||||||
bold: true,
|
text: "\tGithub is the best",
|
||||||
}),
|
bold: true,
|
||||||
],
|
}),
|
||||||
}),
|
],
|
||||||
],
|
}),
|
||||||
}],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Used to export the file into a .docx file
|
// Used to export the file into a .docx file
|
||||||
@ -56,6 +58,7 @@ Packer.toBuffer(doc).then((buffer) => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
<!-- cspell:disable-next-line -->
|
||||||
<img alt="clippy the assistant" src="./clippy.png">
|
<img alt="clippy the assistant" src="./clippy.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<img src="https://i.imgur.com/37uBGhO.gif" alt="drawing" style="width:200px;"/>
|
<img src="https://i.imgur.com/37uBGhO.gif" alt="drawing" style="width:200px;"/>
|
||||||
|
|
||||||
> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
|
> Easily generate and modify .docx files with JS/TS. Works for Node and on the Browser. :100:
|
||||||
|
|
||||||
- Simple, declarative API
|
- Simple, declarative API
|
||||||
- 60+ usage examples
|
- 80+ usage examples
|
||||||
- Battle tested, mature, 99%+ coverage
|
- Battle tested, mature, 99.9%+ coverage
|
||||||
|
|
||||||
[GitHub](https://github.com/dolanmiu/docx)
|
[GitHub](https://github.com/dolanmiu/docx)
|
||||||
[Get Started](#Welcome)
|
[Get Started](#Welcome)
|
||||||
|
@ -1,37 +1,49 @@
|
|||||||
* [Getting Started](/)
|
- [Getting Started](/)
|
||||||
|
|
||||||
* [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
- Examples
|
||||||
|
|
||||||
* API
|
- [Demos](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
|
|
||||||
* [Documentation](https://docx.js.org/api/)
|
- API
|
||||||
|
|
||||||
* Usage
|
- [Documentation](https://docx.js.org/api/)
|
||||||
|
|
||||||
* [Document](usage/document.md)
|
- Usage
|
||||||
* [Sections](usage/sections.md)
|
|
||||||
* [Paragraph](usage/paragraph.md)
|
|
||||||
* [Text](usage/text.md)
|
|
||||||
* [Image](usage/images.md)
|
|
||||||
* [Headers & Footers](usage/headers-and-footers.md)
|
|
||||||
* [Bullet Points](usage/bullet-points.md)
|
|
||||||
* [Hyperlinks](usage/hyperlinks.md)
|
|
||||||
* [Numbering](usage/numbering.md)
|
|
||||||
* [Tables](usage/tables.md)
|
|
||||||
* [Tab Stops](usage/tab-stops.md)
|
|
||||||
* [Table of Contents](usage/table-of-contents.md)
|
|
||||||
* [Page Numbers](usage/page-numbers.md)
|
|
||||||
* [Change Tracking](usage/change-tracking.md)
|
|
||||||
* [Math](usage/math.md)
|
|
||||||
* [Text Frames](usage/text-frames.md)
|
|
||||||
* Styling
|
|
||||||
* [Styling with JS](usage/styling-with-js.md)
|
|
||||||
* [Styling with XML](usage/styling-with-xml.md)
|
|
||||||
* Exporting
|
|
||||||
|
|
||||||
* [Packers](usage/packers.md)
|
- [Document](usage/document.md)
|
||||||
* Utility
|
- [Sections](usage/sections.md)
|
||||||
|
- [Paragraph](usage/paragraph.md)
|
||||||
|
- [Text Frames](usage/text-frames.md)
|
||||||
|
- [Symbols](usage/symbols.md)
|
||||||
|
- [Text](usage/text.md)
|
||||||
|
- [Images](usage/images.md)
|
||||||
|
- [Headers & Footers](usage/headers-and-footers.md)
|
||||||
|
- [Bullet Points](usage/bullet-points.md)
|
||||||
|
- [Hyperlinks](usage/hyperlinks.md)
|
||||||
|
- [Numbering](usage/numbering.md)
|
||||||
|
- [Tables](usage/tables.md)
|
||||||
|
- [Tabs](usage/tabs.md)
|
||||||
|
- [Table of Contents](usage/table-of-contents.md)
|
||||||
|
- [Page Numbers](usage/page-numbers.md)
|
||||||
|
- [Change Tracking](usage/change-tracking.md)
|
||||||
|
- [Math](usage/math.md)
|
||||||
|
- [Comments](usage/comments.md)
|
||||||
|
- [Footnotes](usage/footnotes.md)
|
||||||
|
- [Fields](usage/fields.md)
|
||||||
|
- Styling
|
||||||
|
- [Styling with JS](usage/styling-with-js.md)
|
||||||
|
- [Styling with XML](usage/styling-with-xml.md)
|
||||||
|
|
||||||
* [Convenience functions](usage/convenience-functions.md)
|
- Exporting
|
||||||
|
|
||||||
* [Contribution Guidelines](contribution-guidelines.md)
|
- [Packers](usage/packers.md)
|
||||||
|
|
||||||
|
- Modifying Existing Documents
|
||||||
|
|
||||||
|
- [Patcher](usage/patcher.md)
|
||||||
|
|
||||||
|
- Utility
|
||||||
|
|
||||||
|
- [Convenience functions](usage/convenience-functions.md)
|
||||||
|
|
||||||
|
- [Contribution Guidelines](contribution-guidelines.md)
|
||||||
|
@ -1,18 +1,28 @@
|
|||||||
# Contribution Guidelines
|
# Contribution Guidelines
|
||||||
|
|
||||||
- Include documentation reference(s) at the top of each file:
|
- Include documentation reference(s) at the top of each file as a comment. For example:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// http://officeopenxml.com/WPdocument.php
|
// http://officeopenxml.com/WPdocument.php
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!-- cSpell:ignore datypic -->
|
||||||
|
It can be a link to `officeopenxml.com` or `datypic.com` etc.
|
||||||
|
It could also be a reference to the official ECMA-376 standard: https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
|
||||||
|
|
||||||
|
- Include a portion of the schema as a comment for cross reference. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// <xsd:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="1"/>
|
||||||
|
```
|
||||||
|
|
||||||
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
||||||
|
|
||||||
- Follow the `TSLint` rules
|
- Follow the `ESLint` rules
|
||||||
|
|
||||||
## Always think about the user
|
## Always think about the user
|
||||||
|
|
||||||
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
Put yourself in their position, and imagine how they would feel about the feature you wrote.
|
||||||
|
|
||||||
1. Is it easy to use?
|
1. Is it easy to use?
|
||||||
2. Has it been documented well?
|
2. Has it been documented well?
|
||||||
@ -26,13 +36,15 @@ Please write good commit messages when making a commit: https://chris.beams.io/p
|
|||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
|
<!-- cspell:disable -->
|
||||||
```
|
```
|
||||||
c // What?
|
c // What?
|
||||||
rtl // Adding acryonyms without explaining anything else is not helpful
|
rtl // Adding acronyms without explaining anything else is not helpful
|
||||||
works! // Glad its working, but the message is not helpful
|
works! // Glad its working, but the message is not helpful
|
||||||
demo updated // Getting better, but capitalize the first letter
|
demo updated // Getting better, but capitalize the first letter
|
||||||
Unesesary coment removed // Make sure to use correct spelling
|
Unesesary coment removed // Make sure to use correct spelling
|
||||||
```
|
```
|
||||||
|
<!-- cspell:enable -->
|
||||||
|
|
||||||
**Do**
|
**Do**
|
||||||
|
|
||||||
@ -42,9 +54,9 @@ Unesesary coment removed // Make sure to use correct spelling
|
|||||||
public float(tableFloatOptions: ITableFloatOptions): Table
|
public float(tableFloatOptions: ITableFloatOptions): Table
|
||||||
```
|
```
|
||||||
|
|
||||||
## Delcariative API
|
## Declarative API
|
||||||
|
|
||||||
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
|
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to declarative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
|
||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/docsify-plugin-carbon@1/index.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
name: "docx",
|
name: "docx",
|
||||||
@ -24,6 +25,12 @@
|
|||||||
subMaxLevel: 2,
|
subMaxLevel: 2,
|
||||||
search: "auto",
|
search: "auto",
|
||||||
coverpage: true,
|
coverpage: true,
|
||||||
|
plugins: [
|
||||||
|
// Change to your Carbon property ID
|
||||||
|
// cSpell:disable
|
||||||
|
DocsifyCarbon.create("CEAIP237", "docx"),
|
||||||
|
// cSpell:enable
|
||||||
|
],
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||||
@ -31,6 +38,7 @@
|
|||||||
<script src="https://unpkg.com/docsify-copy-code@2"></script>
|
<script src="https://unpkg.com/docsify-copy-code@2"></script>
|
||||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||||
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
|
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/docsify-sign-off-sheet@1.0.0/dist/index.iife.js"></script>
|
||||||
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
|
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -12,7 +12,7 @@ const doc = new Document({
|
|||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Bullet points",
|
text: "Bullet points",
|
||||||
bullet: {
|
bullet: {
|
||||||
level: 0 //How deep you want the bullet to be
|
level: 0 // How deep you want the bullet to be. Maximum level is 9
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
|
@ -59,3 +59,18 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you want to express a style changes, you can add a `revision` to a `TextRun` which need to include all previous style attributes.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new TextRun({
|
||||||
|
bold: true,
|
||||||
|
text: "This text is now bold and was previously not",
|
||||||
|
revision: {
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
bold: false,
|
||||||
|
}
|
||||||
|
}).break()
|
||||||
|
````
|
||||||
|
17
docs/usage/comments.md
Normal file
17
docs/usage/comments.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Comments
|
||||||
|
|
||||||
|
!> Comments requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
To add comments in `docx`, a `comments` block is specified in the `Document`. This block defines all the comments in your document. Each comment has an `id`, which you then reference later.
|
||||||
|
|
||||||
|
In the spot you want to add a comment, you simply add a `CommentRangeStart` and a `CommentRangeEnd` to specify where the comment starts and ends.
|
||||||
|
|
||||||
|
Alternatively, you can use `CommentReference` to specify a comment at a specific singular point.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/73-comments.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/73-comments.ts_
|
@ -22,20 +22,19 @@ const doc = new docx.Document({
|
|||||||
|
|
||||||
### Full list of options:
|
### Full list of options:
|
||||||
|
|
||||||
|
- creator
|
||||||
* creator
|
- description
|
||||||
* description
|
- title
|
||||||
* title
|
- subject
|
||||||
* subject
|
- keywords
|
||||||
* keywords
|
- lastModifiedBy
|
||||||
* lastModifiedBy
|
- revision
|
||||||
* revision
|
- externalStyles
|
||||||
* externalStyles
|
- styles
|
||||||
* styles
|
- numbering
|
||||||
* numbering
|
- footnotes
|
||||||
* footnotes
|
- hyperlinks
|
||||||
* hyperlinks
|
- background
|
||||||
* background
|
|
||||||
|
|
||||||
### Change background color of Document
|
### Change background color of Document
|
||||||
|
|
||||||
@ -55,3 +54,87 @@ You can mix and match whatever properties you want, or provide no properties.
|
|||||||
|
|
||||||
Various parts of the API require positioning arguments. The units are "20ths of a point" from the [OOXML](http://officeopenxml.com/index.php) specification.
|
Various parts of the API require positioning arguments. The units are "20ths of a point" from the [OOXML](http://officeopenxml.com/index.php) specification.
|
||||||
See [Lars Corneliussen's blog post](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/) for more information and how to convert units.
|
See [Lars Corneliussen's blog post](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/) for more information and how to convert units.
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
Compatibility Settings are optional settings used to preserve visual fidelity of documents created in earlier word processing applications. Some of these settings provide ability for specific behaviors, described in detail below; and others simply instruct applications to mimic the behavior of an existing word processing application.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new docx.Document({
|
||||||
|
compatibility: {
|
||||||
|
version: 15,
|
||||||
|
doNotExpandShiftReturn: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compatibility Options
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| ----------------------------------- | --------- | -------- | ---------------------------- |
|
||||||
|
| version | `number` | Optional | `15`, `16`, `17` |
|
||||||
|
| useSingleBorderforContiguousCells | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| wordPerfectJustification | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| noTabStopForHangingIndent | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| noLeading | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| spaceForUnderline | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| noColumnBalance | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| balanceSingleByteDoubleByteWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| noExtraLineSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotLeaveBackslashAlone | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| underlineTrailingSpaces | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotExpandShiftReturn | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| spacingInWholePoints | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| lineWrapLikeWord6 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| printBodyTextBeforeHeader | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| printColorsBlack | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| spaceWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| showBreaksInFrames | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| subFontBySize | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| suppressBottomSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| suppressTopSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| suppressSpacingAtTopOfPage | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| suppressTopSpacingWP | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| suppressSpBfAfterPgBrk | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| swapBordersFacingPages | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| convertMailMergeEsc | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| truncateFontHeightsLikeWP6 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| macWordSmallCaps | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| usePrinterMetrics | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotSuppressParagraphBorders | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| wrapTrailSpaces | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| footnoteLayoutLikeWW8 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| shapeLayoutLikeWW8 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| alignTablesRowByRow | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| forgetLastTabAlignment | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| adjustLineHeightInTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| autoSpaceLikeWord95 | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| noSpaceRaiseLower | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotUseHTMLParagraphAutoSpacing | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| layoutRawTableWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| layoutTableRowsApart | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useWord97LineBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotBreakWrappedTables | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotSnapToGridInCell | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| selectFieldWithFirstOrLastCharacter | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| applyBreakingRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotWrapTextWithPunctuation | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotUseEastAsianBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useWord2002TableStyleRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| growAutofit | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useFELayout | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useNormalStyleForList | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotUseIndentAsNumberingTabStop | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useAlternateEastAsianLineBreakRules | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| allowSpaceOfSameStyleInTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotSuppressIndentation | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotAutofitConstrainedTables | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| autofitToFirstFixedWidthCell | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| underlineTabInNumberingList | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| displayHangulFixedWidth | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| splitPgBreakAndParaMark | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotVerticallyAlignCellWithSp | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| doNotBreakConstrainedForcedTable | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| ignoreVerticalAlignmentInTextboxes | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| useAnsiKerningPairs | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
| cachedColumnBalance | `boolean` | Optional | `true`, `false`, `undefined` |
|
||||||
|
42
docs/usage/footnotes.md
Normal file
42
docs/usage/footnotes.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Footnotes
|
||||||
|
|
||||||
|
!> Footnotes requires an understanding of [Sections](usage/sections.md).
|
||||||
|
|
||||||
|
Use footnotes and endnotes to explain, comment on, or provide references to something in a document. Usually, footnotes appear at the bottom of the page.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new Document({
|
||||||
|
footnotes: {
|
||||||
|
1: { children: [new Paragraph("Foo"), new Paragraph("Bar")] },
|
||||||
|
2: { children: [new Paragraph("Test")] },
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Hello"],
|
||||||
|
}),
|
||||||
|
new FootnoteReferenceRun(1),
|
||||||
|
new TextRun({
|
||||||
|
children: [" World!"],
|
||||||
|
}),
|
||||||
|
new FootnoteReferenceRun(2),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Footnotes requires an entry into the `footnotes` array in the `Document` constructor, and a `FootnoteReferenceRun` in the `Paragraph` constructor.
|
||||||
|
|
||||||
|
`footnotes` is an object of number to `Footnote` objects. The number is the reference number, and the `Footnote` object is the content of the footnote. The `Footnote` object has a `children` property, which is an array of `Paragraph` objects.
|
||||||
|
|
||||||
|
`FootnoteReferenceRun` is a `Run` object, which are added to `Paragraph`s. It takes a number as a parameter, which is the reference number of the footnote.
|
@ -8,24 +8,24 @@ Every Section has a sections which you can define its Headers and Footers:
|
|||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
sections: [{
|
sections: [{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({ // The standard default header
|
default: new Header({ // The standard default header on every page or header on odd pages when the 'Different Odd & Even Pages' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
first: new Header({ // The first header
|
first: new Header({ // The header on first page when the 'Different First Page' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
even: new Header({ // The header on every other page
|
even: new Header({ // The header on even pages when the 'Different Odd & Even Pages' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: new Footer({ // The standard default footer
|
default: new Footer({ // The standard default footer on every page or footer on odd pages when the 'Different Odd & Even Pages' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
first: new Footer({ // The first footer
|
first: new Footer({ // The footer on first page when the 'Different First Page' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
even: new Footer({ // The footer on every other page
|
even: new Footer({ // The footer on even pages when the 'Different Odd & Even Pages' option is activated
|
||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -42,6 +42,17 @@ Example showing basic header and footer
|
|||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts_
|
||||||
|
|
||||||
|
## Different First Page
|
||||||
|
|
||||||
|
To specify `'Different First Page'`, set `titlePage: true` in the sections array as shown below.
|
||||||
|
|
||||||
|
```
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
titlePage: true,
|
||||||
|
```
|
||||||
|
|
||||||
## Multiple Headers and Footers
|
## Multiple Headers and Footers
|
||||||
|
|
||||||
More headers and footers can be accomplished by creating more `Section`. New headers and footers can be set per `Section`
|
More headers and footers can be accomplished by creating more `Section`. New headers and footers can be set per `Section`
|
||||||
|
@ -252,13 +252,36 @@ const image = new ImageRun({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Alternative Text
|
||||||
|
|
||||||
|
Specifies common non-visual DrawingML properties. A name, title and description for a picture can be specified.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const image = new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
altText: {
|
||||||
|
title: "This is an ultimate title",
|
||||||
|
description: "This is an ultimate image",
|
||||||
|
name: "My Ultimate Image",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| ----------- | -------- | -------- | ------------------------------------ |
|
||||||
|
| name | `string` | Required | `Specimen A` |
|
||||||
|
| title | `string` | Required | `My awesome title of my image` |
|
||||||
|
| description | `string` | Required | `My awesome description of my image` |
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### Add image to the document
|
### Add image to the document
|
||||||
|
|
||||||
Importing Images from file system path
|
Importing Images from file system path
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/5-images.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/5-images.ts ":include")
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_
|
||||||
|
|
||||||
@ -266,7 +289,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/5-images.ts_
|
|||||||
|
|
||||||
Example showing how to add image to headers and footers
|
Example showing how to add image to headers and footers
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/9-images-in-header-and-footer.ts ":include")
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_
|
||||||
|
|
||||||
@ -274,6 +297,6 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-an
|
|||||||
|
|
||||||
Example showing how to float images on top of text and optimally give a `margin`
|
Example showing how to float images on top of text and optimally give a `margin`
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/38-text-wrapping.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/38-text-wrapping.ts ":include")
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_
|
||||||
|
@ -37,7 +37,7 @@ sub-sublists, etc. Each level includes the following properties:
|
|||||||
numbers from each numbering level before this one. Thus a level
|
numbers from each numbering level before this one. Thus a level
|
||||||
text of `%d)` with a number format of `lowerLetter` would result in
|
text of `%d)` with a number format of `lowerLetter` would result in
|
||||||
the sequence "a)", "b)", ...
|
the sequence "a)", "b)", ...
|
||||||
* and a few others, which you can see in the OXML spec section 17.9.6
|
* and a few others, which you can see in the OOXML spec section 17.9.6
|
||||||
|
|
||||||
## Document-level bullets/numbering definitions (concrete)
|
## Document-level bullets/numbering definitions (concrete)
|
||||||
|
|
||||||
@ -86,3 +86,34 @@ topLevelP.setNumbering(concrete, 0);
|
|||||||
subP.setNumbering(concrete, 1);
|
subP.setNumbering(concrete, 1);
|
||||||
subSubP.setNumbering(concrete, 2);
|
subSubP.setNumbering(concrete, 2);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Unindent numbering
|
||||||
|
|
||||||
|
Default:1. test
|
||||||
|
|
||||||
|
After:1.test
|
||||||
|
|
||||||
|
Use default numbering have indent,If you want unindent numbering
|
||||||
|
|
||||||
|
How to custom number see the demo:
|
||||||
|
https://runkit.com/dolanmiu/docx-demo3
|
||||||
|
|
||||||
|
```ts
|
||||||
|
|
||||||
|
enum LevelSuffix {
|
||||||
|
NOTHING = "nothing",
|
||||||
|
SPACE = "space",
|
||||||
|
TAB = "tab"
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom numbering
|
||||||
|
const levels=[
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "decimal",
|
||||||
|
text: "%1.",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
suffix: LevelSuffix.NOTHING, // Cancel intent
|
||||||
|
}]
|
||||||
|
|
||||||
|
```
|
||||||
|
@ -60,29 +60,29 @@ const doc = new Document({
|
|||||||
|
|
||||||
This is the list of options for a paragraph. A detailed explanation is below:
|
This is the list of options for a paragraph. A detailed explanation is below:
|
||||||
|
|
||||||
| Property | Type | Mandatory? | Possible Values |
|
| Property | Type | Mandatory? | Possible Values |
|
||||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- |
|
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [text](#text) | `string` | Optional | |
|
| [text](#text) | `string` | Optional | |
|
||||||
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
||||||
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
||||||
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||||
| [outlineLevel](#outline-level) | `number` | Optional | |
|
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||||
| alignment | `AlignmentType` | Optional | |
|
| alignment | `AlignmentType` | Optional | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
|
||||||
| heading | `HeadingLevel` | Optional | |
|
| heading | `HeadingLevel` | Optional | |
|
||||||
| bidirectional | `boolean` | Optional | |
|
| bidirectional | `boolean` | Optional | |
|
||||||
| thematicBreak | `boolean` | Optional | |
|
| thematicBreak | `boolean` | Optional | |
|
||||||
| pageBreakBefore | `boolean` | Optional | |
|
| pageBreakBefore | `boolean` | Optional | |
|
||||||
| contextualSpacing | `boolean` | Optional | |
|
| contextualSpacing | `boolean` | Optional | |
|
||||||
| indent | `IIndentAttributesProperties` | Optional | |
|
| indent | `IIndentAttributesProperties` | Optional | |
|
||||||
| keepLines | `boolean` | Optional | |
|
| keepLines | `boolean` | Optional | |
|
||||||
| keepNext | `boolean` | Optional | |
|
| keepNext | `boolean` | Optional | |
|
||||||
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
||||||
| style | `string` | Optional | |
|
| style | `string` | Optional | |
|
||||||
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||||
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
||||||
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||||
| [widowControl](#widow-control) | `boolean` | Optional | |
|
| [widowControl](#widow-control) | `boolean` | Optional | |
|
||||||
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
||||||
|
|
||||||
## Text
|
## Text
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ const paragraph = new Paragraph({
|
|||||||
|
|
||||||
## Border
|
## Border
|
||||||
|
|
||||||
Add borders to a `Paragraph`. Good for making the `Paragraph` stand out
|
Add borders to a `Paragraph`. Good for making the `Paragraph` stand out. Border top and border bottom can be used as a horizontal rule (also known as horizontal line).
|
||||||
|
|
||||||
#### IBorderPropertyOptions
|
#### IBorderPropertyOptions
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ Add borders to a `Paragraph`. Good for making the `Paragraph` stand out
|
|||||||
| -------- | -------- | -------- |
|
| -------- | -------- | -------- |
|
||||||
| color | `string` | Required |
|
| color | `string` | Required |
|
||||||
| space | `number` | Required |
|
| space | `number` | Required |
|
||||||
| value | `string` | Required |
|
| style | `string` | Required |
|
||||||
| size | `number` | Required |
|
| size | `number` | Required |
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
@ -135,13 +135,13 @@ const paragraph = new Paragraph({
|
|||||||
top: {
|
top: {
|
||||||
color: "auto",
|
color: "auto",
|
||||||
space: 1,
|
space: 1,
|
||||||
value: "single",
|
style: "single",
|
||||||
size: 6,
|
size: 6,
|
||||||
},
|
},
|
||||||
bottom: {
|
bottom: {
|
||||||
color: "auto",
|
color: "auto",
|
||||||
space: 1,
|
space: 1,
|
||||||
value: "single",
|
style: "single",
|
||||||
size: 6,
|
size: 6,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -180,12 +180,14 @@ Adding spacing between paragraphs
|
|||||||
|
|
||||||
### ISpacingProperties
|
### ISpacingProperties
|
||||||
|
|
||||||
| Property | Type | Notes | Possible Values |
|
| Property | Type | Notes | Possible Values |
|
||||||
| -------- | -------------- | -------- | ----------------------------- |
|
| -------- | -------------- | -------- | -------------------------------------- |
|
||||||
| after | `number` | Optional | |
|
| after | `number` | Optional | |
|
||||||
| before | `number` | Optional | |
|
| before | `number` | Optional | |
|
||||||
| line | `number` | Optional | |
|
| line | `number` | Optional | |
|
||||||
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `AUTO` |
|
| lineRule | `LineRuleType` | Optional | `AT_LEAST`, `EXACTLY`, `EXACT`, `AUTO` |
|
||||||
|
|
||||||
|
Note: The `lineRule` property has different values depending on the version of Word you are using. The `EXACTLY` value is only available in Word 2016 and above. Use `EXACT` for greater support, including LibreOffice etc. Read this issue for more information: https://github.com/dolanmiu/docx/issues/1773.
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
@ -303,4 +305,12 @@ Example: https://github.com/dolanmiu/docx/blob/master/demo/15-page-break-before.
|
|||||||
|
|
||||||
## Page break control
|
## Page break control
|
||||||
|
|
||||||
Paragraphs have `.keepLines()` and `.keepNext()` methods that allow restricting page breaks within and between paragraphs. See [this Microsoft article](https://support.office.com/en-us/article/Keep-lines-and-paragraphs-together-d72af534-926f-4c4b-830a-abfc2daa3bfa) for more details)
|
Paragraphs have `keepLines` and `keepNext` properties that allow restricting page breaks within and between paragraphs. See [this Microsoft article](https://support.office.com/en-us/article/Keep-lines-and-paragraphs-together-d72af534-926f-4c4b-830a-abfc2daa3bfa) for more details.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Stay on the same page",
|
||||||
|
keepLines: true,
|
||||||
|
keepNext: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
94
docs/usage/patcher.md
Normal file
94
docs/usage/patcher.md
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
# Patcher
|
||||||
|
|
||||||
|
The patcher allows you to modify existing documents, and add new content to them.
|
||||||
|
|
||||||
|
!> The Patcher requires an understanding of [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { patchDocument } from "docx";
|
||||||
|
|
||||||
|
patchDocument(fs.readFileSync("My Document.docx"), {
|
||||||
|
patches: {
|
||||||
|
// Patches here
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Patches
|
||||||
|
|
||||||
|
The patcher takes in a `patches` object, which is a map of `string` to `Patch`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface Patch {
|
||||||
|
type: PatchType;
|
||||||
|
children: FileChild[] | ParagraphChild[];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| -------- | --------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| type | `PatchType` | Required | `DOCUMENT`, `PARAGRAPH` |
|
||||||
|
| children | `FileChild[] or ParagraphChild[]` | Required | The contents to replace with. A `FileChild` is a `Paragraph` or `Table`, whereas a `ParagraphChild` is typical `Paragraph` children. |
|
||||||
|
|
||||||
|
### How to patch existing document
|
||||||
|
|
||||||
|
1. Open your existing word document in your favorite Word Processor
|
||||||
|
2. Write tags in the document where you want to patch in a mustache style notation. For example, `{{my_patch}}` and `{{my_second_patch}}`.
|
||||||
|
3. Run the patcher with the patches as a key value pair.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### Word Document
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Patcher
|
||||||
|
|
||||||
|
?> Notice how there is no handlebar notation in the key.
|
||||||
|
|
||||||
|
The patch can be as simple as a string, or as complex as a table. Images, hyperlinks, and other complex elements within the `docx` library are also supported.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
patchDocument(fs.readFileSync("My Document.docx"), {
|
||||||
|
patches: {
|
||||||
|
my_patch: {
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Sir. "), new TextRun("John Doe"), new TextRun("(The Conqueror)")],
|
||||||
|
},
|
||||||
|
my_second_patch: {
|
||||||
|
type: PatchType.DOCUMENT,
|
||||||
|
children: [
|
||||||
|
new Paragraph("Lorem ipsum paragraph"),
|
||||||
|
new Paragraph("Another paragraph"),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a "),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Google Link",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
link: "https://www.google.co.uk",
|
||||||
|
}),
|
||||||
|
new ImageRun({ data: fs.readFileSync("./demo/images/dog.png"), transformation: { width: 100, height: 100 } }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/85-template-document.ts_
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/85-template-document.ts ":include :type=code typescript")
|
@ -146,7 +146,7 @@ const doc = new Document({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up unstyled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up un-styled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
||||||
|
|
||||||
### Document defaults
|
### Document defaults
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ For these properties, the rules state the following conflict resolution in case
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### Declaritive styles
|
### Declarative styles
|
||||||
|
|
||||||
Importing Images from file system path
|
Importing Images from file system path
|
||||||
|
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
# Tab Stops
|
|
||||||
|
|
||||||
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
|
||||||
|
|
||||||
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Simply declare the tab stops on the paragraph, as shown below. Use the tab character `\t` to indicate the tab position within the `text` property of a `TextRun`. Adding multiple `tabStops` will mean you can add additional `\t` characters until the desired `tabStop` is selected. Example is shown below.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
children: [new TextRun({ text: "Hey everyone", bold: true}), new TextRun("\t11th November 1999")],
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: TabStopPosition.MAX,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
children: [new TextRun("\t\tSecond tab stop here I come!")],
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: TabStopPosition.MAX,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: TabStopType.LEFT,
|
|
||||||
position: 1000,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
The above shows the use of two tab stops, and how to select/use it.
|
|
||||||
|
|
||||||
You can add multiple tab stops of the same `type` too.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
children: [new TextRun("Multiple \ttab \tstops!")],
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: TabStopPosition.MAX,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: 1000,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Left Tab Stop
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.LEFT,
|
|
||||||
position: 2268,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
2268 is the distance from the left side.
|
|
||||||
|
|
||||||
## Center Tab Stop
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.CENTER,
|
|
||||||
position: 2268,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
2268 is the distance from the center.
|
|
||||||
|
|
||||||
## Right Tab Stop
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: 2268,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
2268 is the distance from the left side.
|
|
||||||
|
|
||||||
## Max Right Tab Stop
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const paragraph = new Paragraph({
|
|
||||||
tabStops: [
|
|
||||||
{
|
|
||||||
type: TabStopType.RIGHT,
|
|
||||||
position: TabStopPosition.MAX,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
|
@ -104,7 +104,7 @@ Here is a list of options you can add to the `table row`:
|
|||||||
| children | `Array<TableCell>` | Required |
|
| children | `Array<TableCell>` | Required |
|
||||||
| cantSplit | `boolean` | Optional |
|
| cantSplit | `boolean` | Optional |
|
||||||
| tableHeader | `boolean` | Optional |
|
| tableHeader | `boolean` | Optional |
|
||||||
| height | `{ height: number, rule: HeightRule }` | Optional |
|
| height | `{ value: number, rule: HeightRule }` | Optional |
|
||||||
|
|
||||||
### Repeat row
|
### Repeat row
|
||||||
|
|
||||||
|
184
docs/usage/tabs.md
Normal file
184
docs/usage/tabs.md
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
# Tabs and Tab Stops
|
||||||
|
|
||||||
|
## Tab Stops
|
||||||
|
|
||||||
|
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
||||||
|
|
||||||
|
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Simply declare the tab stops on the paragraph, as shown below. Use the tab character `\t` or add the `new Tab()` child to indicate the tab position within the `text` property of a `TextRun`. Adding multiple `tabStops` will mean you can add additional `\t` characters until the desired `tabStop` is selected. Example is shown below.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({ text: "Hey everyone", bold: true }),
|
||||||
|
new TextRun("\t11th November 1999"),
|
||||||
|
new TextRun({
|
||||||
|
children: [new Tab(), "11th November 1999"],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [new TextRun("\t\tSecond tab stop here I come!")],
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TabStopType.LEFT,
|
||||||
|
position: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The above shows the use of two tab stops, and how to select/use it.
|
||||||
|
|
||||||
|
You can add multiple tab stops of the same `type` too.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [new TextRun("Multiple \ttab \tstops!")],
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Multiple ", new Tab(), "tab ", new Tab(), "stops!"],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Left Tab Stop
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.LEFT,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
2268 is the distance from the left side.
|
||||||
|
|
||||||
|
### Center Tab Stop
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.CENTER,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
2268 is the distance from the center.
|
||||||
|
|
||||||
|
### Right Tab Stop
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
2268 is the distance from the left side.
|
||||||
|
|
||||||
|
### Max Right Tab Stop
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
||||||
|
|
||||||
|
## Positional Tabs
|
||||||
|
|
||||||
|
> Positional tab allow you to create a tab stop that is relative to the margin, or the page. This is useful if you want to create a table of contents, or a table of figures.
|
||||||
|
|
||||||
|
They are easier to use than the normal tab stops, as you can use the `PositionalTab` class to create a tab stop, and then add the text to the `TextRun` children. Useful for most cases.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Full name"),
|
||||||
|
new TextRun({
|
||||||
|
children: [
|
||||||
|
new PositionalTab({
|
||||||
|
alignment: PositionalTabAlignment.RIGHT,
|
||||||
|
relativeTo: PositionalTabRelativeTo.MARGIN,
|
||||||
|
leader: PositionalTabLeader.DOT,
|
||||||
|
}),
|
||||||
|
"John Doe",
|
||||||
|
],
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Option | Type | Description | Possible Values |
|
||||||
|
| ---------- | ------------------------- | ------------------------------------- | ------------------------------------------------------------- |
|
||||||
|
| alignment | `PositionalTabAlignment` | The alignment of the tab stop | `LEFT`, `RIGHT`, `CENTER` |
|
||||||
|
| relativeTo | `PositionalTabRelativeTo` | The relative position of the tab stop | `MARGIN`, `INDENT` |
|
||||||
|
| leader | `PositionalTabLeader` | The leader of the tab stop | `NONE`, `DOT`, `HYPHEN`, `UNDERSCORE`, `MIDDLE_DOT`, `EQUALS` |
|
@ -151,6 +151,28 @@ const text = new TextRun({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Vanish and SpecVanish
|
||||||
|
|
||||||
|
You may want to hide your text in your document.
|
||||||
|
|
||||||
|
`Vanish` should affect the normal display of text, but an application may have settings to force hidden text to be displayed.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "This text will be hidden",
|
||||||
|
vanish: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`SpecVanish` was typically used to ensure that a paragraph style can be applied to a part of a paragraph, and still appear as in the Table of Contents (which in previous word processors would ignore the use of the style if it were being used as a character style).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "This text will be hidden forever.",
|
||||||
|
specVanish: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Break
|
## Break
|
||||||
|
|
||||||
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
||||||
|
15
logo/logo-animate.svg
Normal file
15
logo/logo-animate.svg
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 1200 600" xml:space="preserve">
|
||||||
|
<style>
|
||||||
|
.st0{fill:#2B579A;}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
path { fill: #fff; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<path id="X" d="m1009.42 294.26 90.58 216.8h-35.63l-76.09-187.21-75.49 187.21h-35.03l92.4-219.21-85.75-203.52h36.23l70.05 176.34 65.82-176.34h34.42l-81.51 205.93z"/>
|
||||||
|
<path id="C" d="M837.51 426.82c0 60.39-32.61 89.38-96.62 89.38h-1.21c-64.01 0-96.62-28.38-96.62-89.38V173.18c0-57.97 32.61-89.38 96.62-89.38h1.21c64.01 0 96.62 31.4 96.62 89.38v72.47H804.9v-61.6c0-49.52-17.51-70.05-64.62-70.05-47.1 0-64.62 20.53-64.62 70.05v231.89c0 49.52 17.51 70.05 64.62 70.05 47.1 0 64.62-20.53 64.62-70.05v-71.86h32.61v82.74z"/>
|
||||||
|
<path id="O" class="st0" d="M450.95 83.82c2.71.26 5.42.49 8.13.79 15.24 1.66 29.25 6.4 40.96 16.68 10.94 9.62 17.43 21.88 20.97 35.84a76.36 76.36 0 0 1 2.28 18.8c-.03 86.6-.01 173.2-.04 259.8a58.86 58.86 0 0 1-8.11 29.93c-7.35 12.68-18.54 19.97-32.83 22.46-12.27 2.14-24.47 1.56-36.32-2.45-17.14-5.81-27.01-18.1-30.48-35.61-.87-4.4-1.03-8.99-1.1-13.51-.16-10-.05-20.01-.05-30.01V168.27c0-7.04 4.19-10.9 11.29-10.25 1.88.17 3.81.59 5.55 1.31 3.12 1.29 4.69 3.69 4.69 7.22-.03 82.93-.03 165.87-.02 248.8 0 15.01 10.45 28.32 24.92 31.6a38.74 38.74 0 0 0 20.16-.6c10.74-3.27 16.83-10.95 19.56-21.5a35.05 35.05 0 0 0 1.14-8.77c.06-87.53.19-175.06-.07-262.59-.05-17.27-7.1-31.7-21.8-41.66-6.46-4.38-13.78-6.65-21.46-7.74-10.77-1.52-21.49-1.19-31.92 2.09-17.94 5.63-28.41 18.23-32.67 36.19a56.84 56.84 0 0 0-1.45 12.93c-.08 86.6-.13 173.2 0 259.8.03 18.77 4.97 36.32 15.53 52 10.75 15.96 26 25.08 44.85 28.24 15.3 2.56 30.51 1.86 45.37-2.6 24.06-7.22 38.48-23.7 44.77-47.69a92.5 92.5 0 0 0 2.74-28.17c-.05-.87-.04-1.74-.04-2.62V155.51c0-7.45 4.58-11.41 12.11-10.44.81.1 1.61.23 2.4.42 3.53.83 6.05 2.82 7.17 6.37v267.31c-.13.56-.33 1.11-.37 1.68a121.32 121.32 0 0 1-8.14 36.58c-13.92 35.27-39.92 54.47-77.59 58.02l-7.78.74h-8.72l-2.57-.37c-6.55-.84-13.21-1.22-19.65-2.61-23.98-5.2-42.64-18.19-55.3-39.33a114.04 114.04 0 0 1-16.33-59.24c-.13-86.17-.04-172.34-.07-258.52 0-6.38.69-12.63 2.23-18.8 3.53-14.09 10.06-26.46 21.12-36.13 11.73-10.26 25.74-14.98 40.98-16.61 2.65-.28 5.3-.52 7.95-.78 2.66.02 5.33.02 8.01.02z"/>
|
||||||
|
<path id="D" d="M295.06 178.01v243.97c0 59.18-32.61 89.38-96.62 89.38H100V88.64h98.43c64.02 0 96.63 30.19 96.63 89.37zm-99.04-59.18h-63.41v362.34h63.41c47.71 0 66.43-19.93 66.43-70.05V188.88c0-50.12-18.72-70.05-66.43-70.05z"/>
|
||||||
|
<path id="bar" d="M1118.5 25h10v550h-10z">
|
||||||
|
<animate attributeName="visibility" values="hidden;visible" dur="2s" repeatCount="indefinite" />
|
||||||
|
</path>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
12
logo/logo.svg
Normal file
12
logo/logo.svg
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" viewBox="0 0 1200 600" xml:space="preserve">
|
||||||
|
<style>
|
||||||
|
.st0{fill:#2B579A;}
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
path { fill: #fff; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<path id="X" d="m1009.42 294.26 90.58 216.8h-35.63l-76.09-187.21-75.49 187.21h-35.03l92.4-219.21-85.75-203.52h36.23l70.05 176.34 65.82-176.34h34.42l-81.51 205.93z"/>
|
||||||
|
<path id="C" d="M837.51 426.82c0 60.39-32.61 89.38-96.62 89.38h-1.21c-64.01 0-96.62-28.38-96.62-89.38V173.18c0-57.97 32.61-89.38 96.62-89.38h1.21c64.01 0 96.62 31.4 96.62 89.38v72.47H804.9v-61.6c0-49.52-17.51-70.05-64.62-70.05-47.1 0-64.62 20.53-64.62 70.05v231.89c0 49.52 17.51 70.05 64.62 70.05 47.1 0 64.62-20.53 64.62-70.05v-71.86h32.61v82.74z"/>
|
||||||
|
<path id="O" class="st0" d="M450.95 83.82c2.71.26 5.42.49 8.13.79 15.24 1.66 29.25 6.4 40.96 16.68 10.94 9.62 17.43 21.88 20.97 35.84a76.36 76.36 0 0 1 2.28 18.8c-.03 86.6-.01 173.2-.04 259.8a58.86 58.86 0 0 1-8.11 29.93c-7.35 12.68-18.54 19.97-32.83 22.46-12.27 2.14-24.47 1.56-36.32-2.45-17.14-5.81-27.01-18.1-30.48-35.61-.87-4.4-1.03-8.99-1.1-13.51-.16-10-.05-20.01-.05-30.01V168.27c0-7.04 4.19-10.9 11.29-10.25 1.88.17 3.81.59 5.55 1.31 3.12 1.29 4.69 3.69 4.69 7.22-.03 82.93-.03 165.87-.02 248.8 0 15.01 10.45 28.32 24.92 31.6a38.74 38.74 0 0 0 20.16-.6c10.74-3.27 16.83-10.95 19.56-21.5a35.05 35.05 0 0 0 1.14-8.77c.06-87.53.19-175.06-.07-262.59-.05-17.27-7.1-31.7-21.8-41.66-6.46-4.38-13.78-6.65-21.46-7.74-10.77-1.52-21.49-1.19-31.92 2.09-17.94 5.63-28.41 18.23-32.67 36.19a56.84 56.84 0 0 0-1.45 12.93c-.08 86.6-.13 173.2 0 259.8.03 18.77 4.97 36.32 15.53 52 10.75 15.96 26 25.08 44.85 28.24 15.3 2.56 30.51 1.86 45.37-2.6 24.06-7.22 38.48-23.7 44.77-47.69a92.5 92.5 0 0 0 2.74-28.17c-.05-.87-.04-1.74-.04-2.62V155.51c0-7.45 4.58-11.41 12.11-10.44.81.1 1.61.23 2.4.42 3.53.83 6.05 2.82 7.17 6.37v267.31c-.13.56-.33 1.11-.37 1.68a121.32 121.32 0 0 1-8.14 36.58c-13.92 35.27-39.92 54.47-77.59 58.02l-7.78.74h-8.72l-2.57-.37c-6.55-.84-13.21-1.22-19.65-2.61-23.98-5.2-42.64-18.19-55.3-39.33a114.04 114.04 0 0 1-16.33-59.24c-.13-86.17-.04-172.34-.07-258.52 0-6.38.69-12.63 2.23-18.8 3.53-14.09 10.06-26.46 21.12-36.13 11.73-10.26 25.74-14.98 40.98-16.61 2.65-.28 5.3-.52 7.95-.78 2.66.02 5.33.02 8.01.02z"/>
|
||||||
|
<path id="D" d="M295.06 178.01v243.97c0 59.18-32.61 89.38-96.62 89.38H100V88.64h98.43c64.02 0 96.63 30.19 96.63 89.37zm-99.04-59.18h-63.41v362.34h63.41c47.71 0 66.43-19.93 66.43-70.05V188.88c0-50.12-18.72-70.05-66.43-70.05z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.4 KiB |
17089
package-lock.json
generated
17089
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
57
package.json
57
package.json
@ -1,21 +1,22 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "7.1.1",
|
"version": "8.0.2",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "rimraf ./build",
|
"pretest": "rimraf ./build",
|
||||||
"test": "TS_NODE_PROJECT=\"tsconfig.spec.json\" mocha -r ts-node/register -r tsconfig-paths/register \"src/**/*.ts\"",
|
"test": "mocha --config=.mocharc.json",
|
||||||
"test.coverage": "nyc npm test",
|
"test.coverage": "nyc npm test",
|
||||||
"test.watch": "npm test -- --watch",
|
"test.watch": "npm test -- --watch",
|
||||||
"prepublishOnly": "npm run build --production",
|
"prepublishOnly": "npm run build --production",
|
||||||
"lint": "tslint --project .",
|
"lint": "eslint -c .eslintrc.js --ext .ts src",
|
||||||
"build": "npm run webpack && npm run fix-types",
|
"build": "npm run webpack && npm run fix-types",
|
||||||
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
|
"webpack": "rimraf ./build && webpack --config ./webpack.config.ts",
|
||||||
"demo": "npm run build && npm run ts-node --skip-project ./demo",
|
"demo": "npm run build && npm run ts-node --skip-project ./demo",
|
||||||
"typedoc": "rimraf ./build && typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
"typedoc": "rimraf ./build && typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
||||||
"style": "prettier -l \"src/**/*.ts\"",
|
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||||
"style.fix": "npm run style -- --write",
|
"style.fix": "npm run style -- --write",
|
||||||
|
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
||||||
"fix-types": "ts-node --skip-project scripts/types-absolute-fixer.ts",
|
"fix-types": "ts-node --skip-project scripts/types-absolute-fixer.ts",
|
||||||
"e2e": "ts-node scripts/e2e.ts",
|
"e2e": "ts-node scripts/e2e.ts",
|
||||||
"serve.docs": "cd docs && docsify serve",
|
"serve.docs": "cd docs && docsify serve",
|
||||||
@ -27,9 +28,7 @@
|
|||||||
"lint"
|
"lint"
|
||||||
],
|
],
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"build"
|
||||||
"build",
|
|
||||||
"template"
|
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -49,9 +48,9 @@
|
|||||||
],
|
],
|
||||||
"types": "./build/index.d.ts",
|
"types": "./build/index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^16.0.0",
|
"@types/node": "^18.0.0",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"nanoid": "^3.1.20",
|
"nanoid": "^3.3.4",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xml-js": "^1.6.8"
|
"xml-js": "^1.6.8"
|
||||||
},
|
},
|
||||||
@ -60,23 +59,34 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/dolanmiu/docx/issues"
|
"url": "https://github.com/dolanmiu/docx/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/dolanmiu/docx#readme",
|
"homepage": "https://docx.js.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.15",
|
"@types/chai": "^4.2.15",
|
||||||
"@types/glob": "^7.1.4",
|
"@types/chai-as-promised": "^7.1.5",
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^10.0.0",
|
||||||
"@types/prompt": "^1.1.1",
|
"@types/prompt": "^1.1.1",
|
||||||
"@types/request-promise": "^4.1.42",
|
"@types/request-promise": "^4.1.42",
|
||||||
"@types/shelljs": "^0.8.9",
|
"@types/shelljs": "^0.8.11",
|
||||||
"@types/sinon": "^10.0.0",
|
"@types/sinon": "^10.0.0",
|
||||||
"@types/unzipper": "^0.10.4",
|
"@types/unzipper": "^0.10.4",
|
||||||
"@types/webpack": "^5.0.0",
|
"@types/webpack": "^5.0.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||||
|
"@typescript-eslint/parser": "^5.36.1",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"chai": "^3.5.0",
|
"chai": "^4.3.6",
|
||||||
|
"chai-as-promised": "^7.1.1",
|
||||||
|
"cspell": "^6.2.2",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
"glob": "^7.1.2",
|
"eslint": "^8.23.0",
|
||||||
|
"eslint-plugin-functional": "^5.0.1",
|
||||||
|
"eslint-plugin-import": "^2.26.0",
|
||||||
|
"eslint-plugin-jsdoc": "^40.0.0",
|
||||||
|
"eslint-plugin-no-null": "^1.0.2",
|
||||||
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||||
|
"eslint-plugin-unicorn": "^46.0.0",
|
||||||
|
"glob": "^9.3.0",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"mocha": "^9.0.2",
|
"mocha": "^10.0.0",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"pre-commit": "^1.2.2",
|
"pre-commit": "^1.2.2",
|
||||||
"prettier": "^2.3.1",
|
"prettier": "^2.3.1",
|
||||||
@ -85,20 +95,19 @@
|
|||||||
"replace-in-file": "^6.2.0",
|
"replace-in-file": "^6.2.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^4.0.4",
|
||||||
"shelljs": "^0.8.4",
|
"shelljs": "^0.8.4",
|
||||||
"sinon": "^11.0.0",
|
"sinon": "^15.0.0",
|
||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"ts-loader": "^9.0.0",
|
"ts-loader": "^9.0.0",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"tsconfig-paths": "^3.9.0",
|
"tsconfig-paths": "^4.0.0",
|
||||||
"tslint": "^6.1.3",
|
"tsconfig-paths-webpack-plugin": "^4.0.0",
|
||||||
"tslint-immutable": "^6.0.1",
|
"typedoc": "^0.23.2",
|
||||||
"typedoc": "^0.22.3",
|
"typescript": "5.0.3",
|
||||||
"typescript": "4.4.3",
|
|
||||||
"unzipper": "^0.10.11",
|
"unzipper": "^0.10.11",
|
||||||
"webpack": "^5.28.0",
|
"webpack": "^5.28.0",
|
||||||
"webpack-cli": "^4.6.0"
|
"webpack-cli": "^5.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -6,10 +6,10 @@ const files = glob.sync("build/**/*.d.ts");
|
|||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
replaceInFile({
|
replaceInFile({
|
||||||
files: file,
|
files: file,
|
||||||
from: /"file[a-z/-]*"/gi,
|
from: /"@[a-z/-]*"/gi,
|
||||||
to: (match) => {
|
to: (match) => {
|
||||||
const matchSlug = match.replace(/['"]+/g, "").trim();
|
const matchSlug = match.replace(/['"]+/g, "").replace(/[@]+/g, "").trim();
|
||||||
const levelCount = file.split("/").length - 2;
|
const levelCount = file.split(/[\/\\]/).length - 2;
|
||||||
const backLevels = Array(levelCount).fill("../").join("");
|
const backLevels = Array(levelCount).fill("../").join("");
|
||||||
|
|
||||||
return `"${backLevels}${matchSlug}"`;
|
return `"${backLevels}${matchSlug}"`;
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
import { nanoid } from "nanoid/non-secure";
|
|
||||||
|
|
||||||
let currentCount = 0;
|
|
||||||
|
|
||||||
// Twip - twentieths of a point
|
|
||||||
export const convertMillimetersToTwip = (millimeters: number): number => {
|
|
||||||
return Math.floor((millimeters / 25.4) * 72 * 20);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const convertInchesToTwip = (inches: number): number => {
|
|
||||||
return Math.floor(inches * 72 * 20);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const uniqueNumericId = (): number => {
|
|
||||||
return ++currentCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const uniqueId = (): string => {
|
|
||||||
return nanoid().toLowerCase();
|
|
||||||
};
|
|
@ -2,9 +2,9 @@ import { assert, expect } from "chai";
|
|||||||
import * as sinon from "sinon";
|
import * as sinon from "sinon";
|
||||||
|
|
||||||
import { Formatter } from "@export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
import { Paragraph, TextRun } from "file";
|
import { CoreProperties } from "@file/core-properties";
|
||||||
import { CoreProperties } from "file/core-properties";
|
import { Paragraph, TextRun } from "@file/paragraph";
|
||||||
import { Attributes } from "file/xml-components";
|
import { Attributes } from "@file/xml-components";
|
||||||
|
|
||||||
describe("Formatter", () => {
|
describe("Formatter", () => {
|
||||||
let formatter: Formatter;
|
let formatter: Formatter;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { BaseXmlComponent, IContext, IXmlableObject } from "file/xml-components";
|
import { BaseXmlComponent, IContext, IXmlableObject } from "@file/xml-components";
|
||||||
|
|
||||||
export class Formatter {
|
export class Formatter {
|
||||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
public format(input: BaseXmlComponent, context: IContext = {} as IContext): IXmlableObject {
|
public format(input: BaseXmlComponent, context: IContext = { stack: [] } as unknown as IContext): IXmlableObject {
|
||||||
const output = input.prepForXml(context);
|
const output = input.prepForXml(context);
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Media } from "file";
|
import { Media } from "@file/media";
|
||||||
|
|
||||||
import { ImageReplacer } from "./image-replacer";
|
import { ImageReplacer } from "./image-replacer";
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { IMediaData, Media } from "file/media";
|
import { IMediaData, Media } from "@file/media";
|
||||||
|
|
||||||
export class ImageReplacer {
|
export class ImageReplacer {
|
||||||
public replace(xmlData: string, mediaData: IMediaData[], offset: number): string {
|
public replace(xmlData: string, mediaData: readonly IMediaData[], offset: number): string {
|
||||||
let currentXmlData = xmlData;
|
let currentXmlData = xmlData;
|
||||||
|
|
||||||
mediaData.forEach((image, i) => {
|
mediaData.forEach((image, i) => {
|
||||||
@ -11,7 +11,7 @@ export class ImageReplacer {
|
|||||||
return currentXmlData;
|
return currentXmlData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMediaData(xmlData: string, media: Media): IMediaData[] {
|
public getMediaData(xmlData: string, media: Media): readonly IMediaData[] {
|
||||||
return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0);
|
return media.Array.filter((image) => xmlData.search(`{${image.fileName}}`) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import * as sinon from "sinon";
|
import * as sinon from "sinon";
|
||||||
|
|
||||||
import { File, Footer, Header, Paragraph } from "file";
|
import { File } from "@file/file";
|
||||||
|
import { Footer, Header } from "@file/header";
|
||||||
|
import { ImageRun, Paragraph } from "@file/paragraph";
|
||||||
|
import * as convenienceFunctions from "@util/convenience-functions";
|
||||||
|
|
||||||
import { Compiler } from "./next-compiler";
|
import { Compiler } from "./next-compiler";
|
||||||
|
|
||||||
@ -13,17 +16,28 @@ describe("Compiler", () => {
|
|||||||
compiler = new Compiler();
|
compiler = new Compiler();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
sinon.stub(convenienceFunctions, "uniqueId").callsFake(() => "test");
|
||||||
|
});
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
(convenienceFunctions.uniqueId as sinon.SinonStub).restore();
|
||||||
|
});
|
||||||
|
|
||||||
describe("#compile()", () => {
|
describe("#compile()", () => {
|
||||||
it("should pack all the content", async function () {
|
it("should pack all the content", function () {
|
||||||
this.timeout(99999999);
|
this.timeout(99999999);
|
||||||
const file = new File({
|
const file = new File({
|
||||||
sections: [],
|
sections: [],
|
||||||
|
comments: {
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const zipFile = compiler.compile(file);
|
const zipFile = compiler.compile(file);
|
||||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||||
|
|
||||||
expect(fileNames).is.an.instanceof(Array);
|
expect(fileNames).is.an.instanceof(Array);
|
||||||
expect(fileNames).has.length(16);
|
expect(fileNames).has.length(17);
|
||||||
expect(fileNames).to.include("word/document.xml");
|
expect(fileNames).to.include("word/document.xml");
|
||||||
expect(fileNames).to.include("word/styles.xml");
|
expect(fileNames).to.include("word/styles.xml");
|
||||||
expect(fileNames).to.include("docProps/core.xml");
|
expect(fileNames).to.include("docProps/core.xml");
|
||||||
@ -33,29 +47,38 @@ describe("Compiler", () => {
|
|||||||
expect(fileNames).to.include("word/footnotes.xml");
|
expect(fileNames).to.include("word/footnotes.xml");
|
||||||
expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
|
expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
|
||||||
expect(fileNames).to.include("word/settings.xml");
|
expect(fileNames).to.include("word/settings.xml");
|
||||||
|
expect(fileNames).to.include("word/comments.xml");
|
||||||
expect(fileNames).to.include("word/_rels/document.xml.rels");
|
expect(fileNames).to.include("word/_rels/document.xml.rels");
|
||||||
expect(fileNames).to.include("[Content_Types].xml");
|
expect(fileNames).to.include("[Content_Types].xml");
|
||||||
expect(fileNames).to.include("_rels/.rels");
|
expect(fileNames).to.include("_rels/.rels");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should pack all additional headers and footers", async function () {
|
it("should pack all additional headers and footers", function () {
|
||||||
const file = new File({
|
const file = new File({
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header(),
|
default: new Header({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: new Footer(),
|
default: new Footer({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header(),
|
default: new Header({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: new Footer(),
|
default: new Footer({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
@ -68,7 +91,7 @@ describe("Compiler", () => {
|
|||||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||||
|
|
||||||
expect(fileNames).is.an.instanceof(Array);
|
expect(fileNames).is.an.instanceof(Array);
|
||||||
expect(fileNames).has.length(24);
|
expect(fileNames).has.length(25);
|
||||||
|
|
||||||
expect(fileNames).to.include("word/header1.xml");
|
expect(fileNames).to.include("word/header1.xml");
|
||||||
expect(fileNames).to.include("word/_rels/header1.xml.rels");
|
expect(fileNames).to.include("word/_rels/header1.xml.rels");
|
||||||
@ -97,7 +120,61 @@ describe("Compiler", () => {
|
|||||||
const spy = sinon.spy(compiler["formatter"], "format");
|
const spy = sinon.spy(compiler["formatter"], "format");
|
||||||
|
|
||||||
compiler.compile(file);
|
compiler.compile(file);
|
||||||
expect(spy.callCount).to.equal(12);
|
expect(spy.callCount).to.equal(13);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work with media datas", () => {
|
||||||
|
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||||
|
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||||
|
const file = new File({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [new Paragraph("test")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: Buffer.from("", "base64"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// tslint:disable-next-line: no-string-literal
|
||||||
|
sinon.stub(compiler["imageReplacer"], "getMediaData").returns([
|
||||||
|
{
|
||||||
|
stream: Buffer.from(""),
|
||||||
|
fileName: "test",
|
||||||
|
transformation: {
|
||||||
|
pixels: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
emus: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
compiler.compile(file);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import * as JSZip from "jszip";
|
import * as JSZip from "jszip";
|
||||||
import * as xml from "xml";
|
import * as xml from "xml";
|
||||||
|
|
||||||
import { File } from "file";
|
import { File } from "@file/file";
|
||||||
|
|
||||||
import { Formatter } from "../formatter";
|
import { Formatter } from "../formatter";
|
||||||
import { ImageReplacer } from "./image-replacer";
|
import { ImageReplacer } from "./image-replacer";
|
||||||
import { NumberingReplacer } from "./numbering-replacer";
|
import { NumberingReplacer } from "./numbering-replacer";
|
||||||
|
import { PrettifyType } from "./packer";
|
||||||
|
|
||||||
interface IXmlifyedFile {
|
interface IXmlifyedFile {
|
||||||
readonly data: string;
|
readonly data: string;
|
||||||
@ -18,16 +20,17 @@ interface IXmlifyedFileMapping {
|
|||||||
readonly Numbering: IXmlifyedFile;
|
readonly Numbering: IXmlifyedFile;
|
||||||
readonly Relationships: IXmlifyedFile;
|
readonly Relationships: IXmlifyedFile;
|
||||||
readonly FileRelationships: IXmlifyedFile;
|
readonly FileRelationships: IXmlifyedFile;
|
||||||
readonly Headers: IXmlifyedFile[];
|
readonly Headers: readonly IXmlifyedFile[];
|
||||||
readonly Footers: IXmlifyedFile[];
|
readonly Footers: readonly IXmlifyedFile[];
|
||||||
readonly HeaderRelationships: IXmlifyedFile[];
|
readonly HeaderRelationships: readonly IXmlifyedFile[];
|
||||||
readonly FooterRelationships: IXmlifyedFile[];
|
readonly FooterRelationships: readonly IXmlifyedFile[];
|
||||||
readonly ContentTypes: IXmlifyedFile;
|
readonly ContentTypes: IXmlifyedFile;
|
||||||
readonly CustomProperties: IXmlifyedFile;
|
readonly CustomProperties: IXmlifyedFile;
|
||||||
readonly AppProperties: IXmlifyedFile;
|
readonly AppProperties: IXmlifyedFile;
|
||||||
readonly FootNotes: IXmlifyedFile;
|
readonly FootNotes: IXmlifyedFile;
|
||||||
readonly FootNotesRelationships: IXmlifyedFile;
|
readonly FootNotesRelationships: IXmlifyedFile;
|
||||||
readonly Settings: IXmlifyedFile;
|
readonly Settings: IXmlifyedFile;
|
||||||
|
readonly Comments?: IXmlifyedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Compiler {
|
export class Compiler {
|
||||||
@ -35,47 +38,42 @@ export class Compiler {
|
|||||||
private readonly imageReplacer: ImageReplacer;
|
private readonly imageReplacer: ImageReplacer;
|
||||||
private readonly numberingReplacer: NumberingReplacer;
|
private readonly numberingReplacer: NumberingReplacer;
|
||||||
|
|
||||||
constructor() {
|
public constructor() {
|
||||||
this.formatter = new Formatter();
|
this.formatter = new Formatter();
|
||||||
this.imageReplacer = new ImageReplacer();
|
this.imageReplacer = new ImageReplacer();
|
||||||
this.numberingReplacer = new NumberingReplacer();
|
this.numberingReplacer = new NumberingReplacer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public compile(file: File, prettifyXml?: boolean): JSZip {
|
public compile(file: File, prettifyXml?: boolean | PrettifyType): JSZip {
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
|
||||||
|
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
|
||||||
|
|
||||||
for (const key in xmlifiedFileMapping) {
|
for (const [, obj] of map) {
|
||||||
if (!xmlifiedFileMapping[key]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const obj = xmlifiedFileMapping[key] as IXmlifyedFile | IXmlifyedFile[];
|
|
||||||
|
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
for (const subFile of obj) {
|
for (const subFile of obj as readonly IXmlifyedFile[]) {
|
||||||
zip.file(subFile.path, subFile.data);
|
zip.file(subFile.path, subFile.data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zip.file(obj.path, obj.data);
|
zip.file((obj as IXmlifyedFile).path, (obj as IXmlifyedFile).data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const data of file.Media.Array) {
|
for (const { stream, fileName } of file.Media.Array) {
|
||||||
const mediaData = data.stream;
|
zip.file(`word/media/${fileName}`, stream);
|
||||||
zip.file(`word/media/${data.fileName}`, mediaData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
private xmlifyFile(file: File, prettify?: boolean): IXmlifyedFileMapping {
|
private xmlifyFile(file: File, prettify?: boolean | PrettifyType): IXmlifyedFileMapping {
|
||||||
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
|
const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1;
|
||||||
|
|
||||||
const documentXmlData = xml(
|
const documentXmlData = xml(
|
||||||
this.formatter.format(file.Document.View, {
|
this.formatter.format(file.Document.View, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -102,6 +100,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Document.Relationships, {
|
this.formatter.format(file.Document.Relationships, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -117,7 +116,6 @@ export class Compiler {
|
|||||||
data: (() => {
|
data: (() => {
|
||||||
const xmlData = this.imageReplacer.replace(documentXmlData, documentMediaDatas, documentRelationshipCount);
|
const xmlData = this.imageReplacer.replace(documentXmlData, documentMediaDatas, documentRelationshipCount);
|
||||||
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
|
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
|
||||||
|
|
||||||
return referenedXmlData;
|
return referenedXmlData;
|
||||||
})(),
|
})(),
|
||||||
path: "word/document.xml",
|
path: "word/document.xml",
|
||||||
@ -128,6 +126,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Styles, {
|
this.formatter.format(file.Styles, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -147,6 +146,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.CoreProperties, {
|
this.formatter.format(file.CoreProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -163,6 +163,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Numbering, {
|
this.formatter.format(file.Numbering, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -179,6 +180,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.FileRelationships, {
|
this.formatter.format(file.FileRelationships, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -194,6 +196,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.View, {
|
this.formatter.format(headerWrapper.View, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -217,6 +220,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.Relationships, {
|
this.formatter.format(headerWrapper.Relationships, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -233,6 +237,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.View, {
|
this.formatter.format(footerWrapper.View, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -256,6 +261,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.Relationships, {
|
this.formatter.format(footerWrapper.Relationships, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -272,6 +278,7 @@ export class Compiler {
|
|||||||
this.formatter.format(headerWrapper.View, {
|
this.formatter.format(headerWrapper.View, {
|
||||||
viewWrapper: headerWrapper,
|
viewWrapper: headerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -284,8 +291,10 @@ export class Compiler {
|
|||||||
// TODO: 0 needs to be changed when headers get relationships of their own
|
// TODO: 0 needs to be changed when headers get relationships of their own
|
||||||
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
||||||
|
|
||||||
|
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: xmlData,
|
data: referenedXmlData,
|
||||||
path: `word/header${index + 1}.xml`,
|
path: `word/header${index + 1}.xml`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
@ -294,6 +303,7 @@ export class Compiler {
|
|||||||
this.formatter.format(footerWrapper.View, {
|
this.formatter.format(footerWrapper.View, {
|
||||||
viewWrapper: footerWrapper,
|
viewWrapper: footerWrapper,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -306,8 +316,10 @@ export class Compiler {
|
|||||||
// TODO: 0 needs to be changed when headers get relationships of their own
|
// TODO: 0 needs to be changed when headers get relationships of their own
|
||||||
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
const xmlData = this.imageReplacer.replace(tempXmlData, mediaDatas, 0);
|
||||||
|
|
||||||
|
const referenedXmlData = this.numberingReplacer.replace(xmlData, file.Numbering.ConcreteNumbering);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: xmlData,
|
data: referenedXmlData,
|
||||||
path: `word/footer${index + 1}.xml`,
|
path: `word/footer${index + 1}.xml`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
@ -316,6 +328,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.ContentTypes, {
|
this.formatter.format(file.ContentTypes, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -331,6 +344,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.CustomProperties, {
|
this.formatter.format(file.CustomProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -347,6 +361,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.AppProperties, {
|
this.formatter.format(file.AppProperties, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -362,7 +377,8 @@ export class Compiler {
|
|||||||
data: xml(
|
data: xml(
|
||||||
this.formatter.format(file.FootNotes.View, {
|
this.formatter.format(file.FootNotes.View, {
|
||||||
viewWrapper: file.FootNotes,
|
viewWrapper: file.FootNotes,
|
||||||
file: file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -377,7 +393,8 @@ export class Compiler {
|
|||||||
data: xml(
|
data: xml(
|
||||||
this.formatter.format(file.FootNotes.Relationships, {
|
this.formatter.format(file.FootNotes.Relationships, {
|
||||||
viewWrapper: file.FootNotes,
|
viewWrapper: file.FootNotes,
|
||||||
file: file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -393,6 +410,7 @@ export class Compiler {
|
|||||||
this.formatter.format(file.Settings, {
|
this.formatter.format(file.Settings, {
|
||||||
viewWrapper: file.Document,
|
viewWrapper: file.Document,
|
||||||
file,
|
file,
|
||||||
|
stack: [],
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
indent: prettify,
|
indent: prettify,
|
||||||
@ -404,6 +422,23 @@ export class Compiler {
|
|||||||
),
|
),
|
||||||
path: "word/settings.xml",
|
path: "word/settings.xml",
|
||||||
},
|
},
|
||||||
|
Comments: {
|
||||||
|
data: xml(
|
||||||
|
this.formatter.format(file.Comments, {
|
||||||
|
viewWrapper: file.Document,
|
||||||
|
file,
|
||||||
|
stack: [],
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
indent: prettify,
|
||||||
|
declaration: {
|
||||||
|
standalone: "yes",
|
||||||
|
encoding: "UTF-8",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
path: "word/comments.xml",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ConcreteNumbering } from "file";
|
import { ConcreteNumbering } from "@file/numbering";
|
||||||
|
|
||||||
export class NumberingReplacer {
|
export class NumberingReplacer {
|
||||||
public replace(xmlData: string, concreteNumberings: ConcreteNumbering[]): string {
|
public replace(xmlData: string, concreteNumberings: readonly ConcreteNumbering[]): string {
|
||||||
let currentXmlData = xmlData;
|
let currentXmlData = xmlData;
|
||||||
|
|
||||||
for (const concreteNumbering of concreteNumberings) {
|
for (const concreteNumbering of concreteNumberings) {
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { mock, stub } from "sinon";
|
import { mock, stub } from "sinon";
|
||||||
|
|
||||||
import { File, HeadingLevel, Paragraph } from "file";
|
import { File } from "@file/file";
|
||||||
|
import { HeadingLevel, Paragraph } from "@file/paragraph";
|
||||||
|
|
||||||
import { Packer } from "./packer";
|
import { Packer } from "./packer";
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ describe("Packer", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
file = new File({
|
file = new File({
|
||||||
creator: "Dolan Miu",
|
creator: "Dolan Miu",
|
||||||
revision: "1",
|
revision: 1,
|
||||||
lastModifiedBy: "Dolan Miu",
|
lastModifiedBy: "Dolan Miu",
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
@ -36,6 +37,14 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#toString()", () => {
|
||||||
|
it("should return a non-empty string", async () => {
|
||||||
|
const result = await Packer.toString(file);
|
||||||
|
|
||||||
|
assert.isAbove(result.length, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#toBuffer()", () => {
|
describe("#toBuffer()", () => {
|
||||||
it("should create a standard docx file", async function () {
|
it("should create a standard docx file", async function () {
|
||||||
this.timeout(99999999);
|
this.timeout(99999999);
|
||||||
@ -46,7 +55,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -56,7 +65,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -71,7 +80,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -81,14 +90,14 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#toBlob()", () => {
|
describe("#toBlob()", () => {
|
||||||
it("should create a standard docx file", async () => {
|
it("should create a standard docx file", async () => {
|
||||||
// tslint:disable-next-line: no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
// tslint:disable-next-line: no-empty
|
// tslint:disable-next-line: no-empty
|
||||||
generateAsync: () => mock({}),
|
generateAsync: () => mock({}),
|
||||||
@ -99,7 +108,7 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle exception if it throws any", () => {
|
it("should handle exception if it throws any", () => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const compiler = stub((Packer as any).compiler, "compile");
|
const compiler = stub((Packer as any).compiler, "compile");
|
||||||
|
|
||||||
compiler.throwsException();
|
compiler.throwsException();
|
||||||
@ -109,7 +118,57 @@ describe("Packer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// tslint:disable-next-line:no-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
(Packer as any).compiler.compile.restore();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#toStream()", () => {
|
||||||
|
it("should create a standard docx file", async () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
|
// tslint:disable-next-line: no-empty
|
||||||
|
generateNodeStream: () => ({
|
||||||
|
on: (event: string, cb: () => void) => {
|
||||||
|
if (event === "end") {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
const stream = await Packer.toStream(file);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
stream.on("error", () => {
|
||||||
|
reject(new Error());
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on("end", () => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle exception if it throws any", () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const compiler = stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||||
|
// tslint:disable-next-line: no-empty
|
||||||
|
on: (event: string, cb: () => void) => {
|
||||||
|
if (event === "error") {
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
compiler.throwsException();
|
||||||
|
try {
|
||||||
|
Packer.toStream(file);
|
||||||
|
} catch (error) {
|
||||||
|
assert.isDefined(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(Packer as any).compiler.compile.restore();
|
(Packer as any).compiler.compile.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,31 @@
|
|||||||
import { File } from "file";
|
import { Stream } from "stream";
|
||||||
|
import { File } from "@file/file";
|
||||||
|
|
||||||
import { Compiler } from "./next-compiler";
|
import { Compiler } from "./next-compiler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use blanks to prettify
|
||||||
|
*/
|
||||||
|
export enum PrettifyType {
|
||||||
|
NONE = "",
|
||||||
|
WITH_2_BLANKS = " ",
|
||||||
|
WITH_4_BLANKS = " ",
|
||||||
|
WITH_TAB = "\t",
|
||||||
|
}
|
||||||
|
|
||||||
export class Packer {
|
export class Packer {
|
||||||
public static async toBuffer(file: File, prettify?: boolean): Promise<Buffer> {
|
public static async toString(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
||||||
|
const zip = this.compiler.compile(file, prettify);
|
||||||
|
const zipData = await zip.generateAsync({
|
||||||
|
type: "string",
|
||||||
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
compression: "DEFLATE",
|
||||||
|
});
|
||||||
|
|
||||||
|
return zipData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise<Buffer> {
|
||||||
const zip = this.compiler.compile(file, prettify);
|
const zip = this.compiler.compile(file, prettify);
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "nodebuffer",
|
type: "nodebuffer",
|
||||||
@ -13,7 +36,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async toBase64String(file: File, prettify?: boolean): Promise<string> {
|
public static async toBase64String(file: File, prettify?: boolean | PrettifyType): Promise<string> {
|
||||||
const zip = this.compiler.compile(file, prettify);
|
const zip = this.compiler.compile(file, prettify);
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "base64",
|
type: "base64",
|
||||||
@ -24,7 +47,7 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async toBlob(file: File, prettify?: boolean): Promise<Blob> {
|
public static async toBlob(file: File, prettify?: boolean | PrettifyType): Promise<Blob> {
|
||||||
const zip = this.compiler.compile(file, prettify);
|
const zip = this.compiler.compile(file, prettify);
|
||||||
const zipData = await zip.generateAsync({
|
const zipData = await zip.generateAsync({
|
||||||
type: "blob",
|
type: "blob",
|
||||||
@ -35,5 +58,17 @@ export class Packer {
|
|||||||
return zipData;
|
return zipData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static toStream(file: File, prettify?: boolean | PrettifyType): Stream {
|
||||||
|
const zip = this.compiler.compile(file, prettify);
|
||||||
|
const zipData = zip.generateNodeStream({
|
||||||
|
type: "nodebuffer",
|
||||||
|
streamFiles: true,
|
||||||
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
compression: "DEFLATE",
|
||||||
|
});
|
||||||
|
|
||||||
|
return zipData;
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly compiler = new Compiler();
|
private static readonly compiler = new Compiler();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { XmlAttributeComponent } from "file/xml-components";
|
import { XmlAttributeComponent } from "@file/xml-components";
|
||||||
|
|
||||||
export class AppPropertiesAttributes extends XmlAttributeComponent<{
|
export class AppPropertiesAttributes extends XmlAttributeComponent<{
|
||||||
readonly xmlns: string;
|
readonly xmlns: string;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
import { AppPropertiesAttributes } from "./app-properties-attributes";
|
import { AppPropertiesAttributes } from "./app-properties-attributes";
|
||||||
|
|
||||||
export class AppProperties extends XmlComponent {
|
export class AppProperties extends XmlComponent {
|
||||||
constructor() {
|
public constructor() {
|
||||||
super("Properties");
|
super("Properties");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "@export/formatter";
|
||||||
import { BorderStyle } from "file/border";
|
import { BorderStyle } from "@file/border";
|
||||||
|
|
||||||
import { BorderElement } from "./border";
|
import { BorderElement } from "./border";
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
// <xsd:attribute name="shadow" type="s:ST_OnOff" use="optional"/>
|
// <xsd:attribute name="shadow" type="s:ST_OnOff" use="optional"/>
|
||||||
// <xsd:attribute name="frame" type="s:ST_OnOff" use="optional"/>
|
// <xsd:attribute name="frame" type="s:ST_OnOff" use="optional"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||||
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "../values";
|
import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values";
|
||||||
|
|
||||||
export interface IBorderOptions {
|
export interface IBorderOptions {
|
||||||
readonly style: BorderStyle;
|
readonly style: BorderStyle;
|
||||||
@ -33,7 +33,7 @@ export interface IBorderOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BorderElement extends XmlComponent {
|
export class BorderElement extends XmlComponent {
|
||||||
constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
|
public constructor(elementName: string, { color, size, space, style }: IBorderOptions) {
|
||||||
super(elementName);
|
super(elementName);
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new BordersAttributes({
|
new BordersAttributes({
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user