Compare commits
1129 Commits
Author | SHA1 | Date | |
---|---|---|---|
d6f363b275 | |||
118ea57412 | |||
7c8be4c8a7 | |||
fa9021596f | |||
3ccf4bdfe3 | |||
f2480673ec | |||
e93b8032d8 | |||
5de2d8c7fb | |||
e355fd3d2e | |||
d41ef99c85 | |||
5ec18d6e01 | |||
b4cd3a319c | |||
d894bfa167 | |||
d74db948ba | |||
3ef26c747b | |||
38c8220e9e | |||
86f8259b33 | |||
502db14bba | |||
ef12ada5d7 | |||
977b2b302d | |||
17d02a3d1c | |||
6100ff4c4e | |||
8bb73fb25e | |||
d6cce4ae15 | |||
058304d16b | |||
345d34a2e1 | |||
3839a49d47 | |||
0afe0929a3 | |||
a14a1fbd10 | |||
52f0a6958a | |||
8bdde98db1 | |||
19fc900045 | |||
6bdd9b882a | |||
0d97d428fa | |||
a0b42d7bdb | |||
69ba312a96 | |||
a0c13214e6 | |||
4c8829df28 | |||
3ee3e95410 | |||
806deeaf78 | |||
feb121707d | |||
31c7f034ec | |||
30ab92652c | |||
0407548113 | |||
277845626c | |||
b2af8b970e | |||
542866e18b | |||
f54192809f | |||
f3ba62fd88 | |||
8d4a07302b | |||
d504231124 | |||
173b1e118c | |||
ffba276f0d | |||
b210608e56 | |||
74353104dc | |||
825136d1c9 | |||
b2fea471f1 | |||
e9adb8b0ed | |||
5d6bc039d0 | |||
27638063c8 | |||
f6a4d78ab7 | |||
4061e31400 | |||
74db67689f | |||
2213eb28cb | |||
d1b45d416b | |||
f72f7e7514 | |||
0165cfb3e5 | |||
ef747486c0 | |||
e0b2f59c2f | |||
82bdb301f9 | |||
c7ea26e422 | |||
34b2029efe | |||
37e610d2b3 | |||
4882235d20 | |||
1552ebde11 | |||
d263d0c8a5 | |||
610b2388bb | |||
bcb16cef9b | |||
0f3afd94f3 | |||
60eb686d05 | |||
7f5e43fba9 | |||
ed52ef358b | |||
214afab711 | |||
18a1677588 | |||
cae372e9ad | |||
ea5f9a48ab | |||
dcf755e756 | |||
d445c21ea1 | |||
6db0449ed0 | |||
ae37b1980f | |||
96f76906c4 | |||
19d9619785 | |||
5be195fd91 | |||
e36e9e1cf4 | |||
102d6aa55c | |||
daea8d2868 | |||
700a74fd4c | |||
32a84a5ad0 | |||
3c9f9474ce | |||
1e10686315 | |||
cae6405d9a | |||
a884ce94e5 | |||
065c17de74 | |||
09db2c528a | |||
2adfe532dd | |||
6cbe40cecb | |||
6b9467393e | |||
5125e77431 | |||
ab68ae0092 | |||
38079b6171 | |||
d584290f3d | |||
9b9baa9b4a | |||
c258310560 | |||
af0bf5ced5 | |||
57c480a6c6 | |||
25f7423533 | |||
0c068bb03b | |||
1822473abc | |||
93a7d607b2 | |||
d45213636c | |||
e196d9d917 | |||
cf88e50afd | |||
64e5814c31 | |||
37251c84f8 | |||
a576098639 | |||
2450fe83ce | |||
e1004440d2 | |||
491c7abd1c | |||
364ce6d856 | |||
ffb6b73bb7 | |||
6041c39a26 | |||
c54f0a52f6 | |||
6b87d9c038 | |||
1285304f97 | |||
58fae6b201 | |||
dc1f3aebe9 | |||
8a189161f2 | |||
6667595627 | |||
33befaab09 | |||
c91f135c28 | |||
08f9926e60 | |||
f323b293fb | |||
adc91929b0 | |||
c63cba5a0c | |||
7a48da440b | |||
05dda37b71 | |||
ee43585210 | |||
a6eb8e01df | |||
8c45c30753 | |||
d18cfbc26f | |||
f4af5f9e33 | |||
69adbbc1c1 | |||
4f6a9f734c | |||
8b78f2d200 | |||
26a3fa6946 | |||
f955a18936 | |||
ee1a7818b6 | |||
8e455f1097 | |||
827c46cf47 | |||
61cbee829d | |||
f0ad1e9194 | |||
bbd339f0e4 | |||
858af64dc3 | |||
01e34c1b28 | |||
41acb475a9 | |||
20978f8c24 | |||
265a3dbe21 | |||
627f5b4bf0 | |||
1538c1aaeb | |||
839661e5f8 | |||
fff6244597 | |||
b2280f64a1 | |||
21d53c41d0 | |||
6e94bbb5e5 | |||
7d655cd3f7 | |||
00821677c8 | |||
784de3e430 | |||
3213c4838d | |||
1b9bc8eb1d | |||
bf58d0b864 | |||
28ca8392ed | |||
5238c55bc2 | |||
901f10c387 | |||
defa22ffe5 | |||
84919c0cc0 | |||
1e8ca123b0 | |||
3ae7c6aedf | |||
6a3ed4bbf8 | |||
e632d323c9 | |||
d2b35ab8f2 | |||
e60f39df41 | |||
076431e04d | |||
75ab44403c | |||
e2d6097819 | |||
ab12ff1257 | |||
25a0212f4e | |||
a8993f14d6 | |||
1834cd86da | |||
437de27ed8 | |||
96f08482da | |||
edec2eca7a | |||
9202524d83 | |||
0461907533 | |||
445a2896d2 | |||
e2d8f1b6b1 | |||
7baa696a76 | |||
3f7ca6bbff | |||
36e1c5fe6a | |||
75a03f1576 | |||
437e83ab78 | |||
b8232f7a02 | |||
49eadb0efc | |||
40dc90e585 | |||
0de302d192 | |||
80bab95f6c | |||
ba3d551c9f | |||
d14fe31f97 | |||
057f41e355 | |||
8c9b61b37a | |||
11e54b3e2c | |||
fa7cb0bef1 | |||
3977c8ab3b | |||
e8f92efe05 | |||
994df8531b | |||
3cdf96ee0c | |||
e2f55d52e9 | |||
d6fa33035a | |||
f11bca728f | |||
596761d78d | |||
8a3c8d4664 | |||
fdfce79e87 | |||
88340aa336 | |||
d0f53fdd4b | |||
d657f61e11 | |||
20e6b98770 | |||
5ae824358c | |||
3ea106bd22 | |||
538264dec5 | |||
6bcd1c2c24 | |||
120c3a7bbe | |||
2654799822 | |||
6245635b86 | |||
b4f1c4dd6a | |||
25a7ce3742 | |||
08bc069cbf | |||
0ebdcc30ed | |||
3eca81d3f5 | |||
faefbae3a1 | |||
370fb098ac | |||
c73019d84c | |||
250a1de71e | |||
012963e90a | |||
632f3cd19b | |||
1c8cd325d7 | |||
7bcdaab2f2 | |||
5b58e520f9 | |||
78f6ea6c44 | |||
b5172e73f9 | |||
5cf534ad26 | |||
d53cdb0558 | |||
212adbbffb | |||
99ab2f0ef5 | |||
a8201b2658 | |||
f13e676c3b | |||
61b01836bc | |||
2ee918b845 | |||
e9579d75c4 | |||
97824f1bb5 | |||
884c134b25 | |||
4f3cb49076 | |||
152285ed5a | |||
49b7ac212d | |||
83450e6277 | |||
6d6155c742 | |||
f8da2c311b | |||
f6bcaef5b5 | |||
1a9e71bfa1 | |||
3591e11637 | |||
47533cf4e2 | |||
de03f19b46 | |||
d1472368f6 | |||
b83d2c388f | |||
ee5425bef7 | |||
3fdbca939e | |||
c68dc8c52a | |||
96471ecb45 | |||
a13f898ad3 | |||
b4cce534a5 | |||
e0698554ad | |||
1649d2a0fa | |||
9683e89159 | |||
2bece0bb61 | |||
deb6c42d86 | |||
2b0953bb19 | |||
d25d22508c | |||
6db37eb4fb | |||
af461f8418 | |||
8bdbd1de39 | |||
1bdc93ef59 | |||
c12101fbc6 | |||
d5ba6578b3 | |||
b37aefdc8d | |||
0be7c26798 | |||
bf1d10e893 | |||
7dfb016faa | |||
b2aeb2d83c | |||
8f4c78e2a8 | |||
bd1f5898a8 | |||
05a4ef1702 | |||
da9e6d6664 | |||
e9d3853d93 | |||
5a9d6120a5 | |||
e8410ff692 | |||
3427d220c7 | |||
643e3c2f84 | |||
9b40b5e55e | |||
a622c210ef | |||
9495f30e2d | |||
617af87065 | |||
9aab68a8f8 | |||
c1dd421b27 | |||
8eff6bd0cf | |||
8566c64eab | |||
afd468277e | |||
ca9c992237 | |||
c93b74661b | |||
08ff092638 | |||
2276572902 | |||
43ddeec6e1 | |||
9eaf04f4c7 | |||
c3c29bb119 | |||
ddb34e6a46 | |||
ef3055430b | |||
75cdae1473 | |||
860afe8f28 | |||
f685dbe0d1 | |||
50911fff57 | |||
a7064f4728 | |||
564e9600ea | |||
fcc4202598 | |||
bfbe59cb84 | |||
06abde2425 | |||
75c3c2f985 | |||
fefefdd473 | |||
db59474f1e | |||
1d5e806ff4 | |||
bf4885c7cf | |||
3b289be5ce | |||
2bb7e08ade | |||
b571a7550f | |||
721de30587 | |||
f16126e948 | |||
40d1a3a7c2 | |||
0d4c7a5fc0 | |||
5d401dfb27 | |||
a37c9d8f2f | |||
10ab3c70bf | |||
591b2f4e04 | |||
2536fbe752 | |||
33549d5ec3 | |||
720c6172e3 | |||
bbad2f5cde | |||
d2a0baa221 | |||
ad62f5459b | |||
dfb910defb | |||
04b6d8e54a | |||
d2dded860d | |||
38f2638ea0 | |||
2b874e3f69 | |||
b43ed12c84 | |||
59be381213 | |||
172c333357 | |||
c5eb3d5670 | |||
44b95f2f15 | |||
bd888219fc | |||
2842619196 | |||
b2de74a0e6 | |||
7aa4134e2b | |||
cc36ea7542 | |||
c11af71ed7 | |||
a9d4ebc898 | |||
d2f82052b4 | |||
f88a309d55 | |||
418adca9f3 | |||
993f8f81f7 | |||
99718784f1 | |||
59fc1ed632 | |||
cb74868247 | |||
bd6ae2c0dc | |||
60a599a550 | |||
4ac55a787e | |||
cb52a1ef42 | |||
7827d158d7 | |||
535f2d75b0 | |||
4f8d435e16 | |||
5ecdb48d43 | |||
a1b9be453b | |||
2502fe7f39 | |||
02487fbb22 | |||
2abff6991f | |||
49e85275c3 | |||
96efdf8b1a | |||
b52a4adaff | |||
a9fc40dad4 | |||
b609a17362 | |||
4b49fdbf8e | |||
fd52c8cf47 | |||
a54c2714db | |||
ad4a843a1e | |||
183062a977 | |||
e685da8cc2 | |||
eea38a6709 | |||
9fdd07e7fe | |||
d8b60d82f3 | |||
629e6a5095 | |||
65c5177daf | |||
b741db3050 | |||
82fef4c2b1 | |||
e45e7ffe06 | |||
099eb1d202 | |||
9da9f31c77 | |||
820e5edc1e | |||
0f1f398e6d | |||
b5503e7b9b | |||
5a005365b2 | |||
2a5e3729e0 | |||
ebc7dca949 | |||
fa710d1ba6 | |||
4b19131dbd | |||
cb699e17b3 | |||
c2c05b0140 | |||
3263984f03 | |||
6f6f1e249c | |||
6380b2d8f3 | |||
9938a8bcc0 | |||
ac5b15d0e3 | |||
ec5a678f05 | |||
bf80311ef7 | |||
58346a8937 | |||
f33d6da65a | |||
9e8d67c4a9 | |||
cbbc4a80e7 | |||
1f51fd7a31 | |||
120d97bc64 | |||
a531713214 | |||
564a055316 | |||
6c29c4fb1f | |||
edbb4ce9f2 | |||
e2574ec23b | |||
3ef8f5311d | |||
552580bc47 | |||
0998d43b8f | |||
b08354494c | |||
f54b9a197d | |||
2d4412ce51 | |||
b566b0f765 | |||
384d144a85 | |||
c97d15cb9f | |||
dfe986331d | |||
72c32378c5 | |||
0c79c0ac83 | |||
1dfc27ba08 | |||
427dc86915 | |||
7bc00926eb | |||
fb65bb4207 | |||
a1cd5e9573 | |||
5497dabaf9 | |||
58dc6fe389 | |||
34c3285426 | |||
cb42c74a8d | |||
a5afce458d | |||
2f687125d1 | |||
5c1a731314 | |||
622331ad24 | |||
3a593a53d3 | |||
31a9111667 | |||
373c890354 | |||
723d76d06f | |||
a24d745d75 | |||
90891cfafd | |||
29f890918c | |||
b0f8f8ddbd | |||
9c89c1ab59 | |||
7a9cb92955 | |||
77edf8862b | |||
bb1604cd8f | |||
816cb54b14 | |||
920bd3c175 | |||
a2a01edc24 | |||
193d0c4239 | |||
d8cc11c5ab | |||
b874051f32 | |||
272e2496f4 | |||
43c199c725 | |||
0e975b3d66 | |||
c6ab47e838 | |||
48c17d51bb | |||
df2315ae4a | |||
e67fd9cb2b | |||
639842332f | |||
2cb7d44a77 | |||
6cd62418a5 | |||
f3ba11b21c | |||
51b1e08a35 | |||
b0d0041ff9 | |||
55c5dd818a | |||
3bebe0ad59 | |||
c5c67fd92a | |||
1486d3de56 | |||
6d8eea40be | |||
0922d49cd3 | |||
f76471f553 | |||
973177676e | |||
5aa878b901 | |||
b99d1fc129 | |||
1590f9ac70 | |||
6c772b956c | |||
9d09ff3518 | |||
d9ad69b7cd | |||
e23d230acb | |||
5ca872cb07 | |||
b179facca2 | |||
db60270e1f | |||
3e2130bc80 | |||
1b336785b4 | |||
6eed0fe0f5 | |||
2f8f69b0c4 | |||
4580a65a84 | |||
661c3e21e4 | |||
32646f8806 | |||
231428852e | |||
46ddf77342 | |||
441afe8c97 | |||
ca9ce01f56 | |||
2b9ce0febd | |||
18760387db | |||
28dabb06cb | |||
50fc9b6274 | |||
367518d504 | |||
efd89f24e6 | |||
4fd2b6f1d3 | |||
5ae541a40d | |||
c9fb9a827d | |||
918faf59c3 | |||
3a9fa49fbb | |||
218a08d793 | |||
416a239708 | |||
d1bdbd397a | |||
a6077b8f16 | |||
8f133ff93a | |||
1f12e159ef | |||
83a7f4664d | |||
728aefc4a7 | |||
40730548bb | |||
d6c2c96757 | |||
b22f565dd0 | |||
41eeac1b05 | |||
18a5f22f4c | |||
2a1161d857 | |||
4b6d3c3e3c | |||
14a1d62148 | |||
1f98d9461b | |||
8dc590746b | |||
de5f5c9a77 | |||
788205b14d | |||
ca5f6a56a5 | |||
bf8dfe6604 | |||
b0ee0305fb | |||
8f6984580a | |||
383c6d769f | |||
9f38a4f48a | |||
475a132ce0 | |||
4111413074 | |||
50209bb435 | |||
b37d2c141d | |||
d19cdcae0c | |||
3f652764e9 | |||
7b5cf690e2 | |||
d674523139 | |||
db7f27a88c | |||
677300e34f | |||
da0fa86345 | |||
78b310e1dd | |||
4541d7c977 | |||
9271b2d11a | |||
942c6d028c | |||
f717126145 | |||
abd5ace85c | |||
a37ff90bd7 | |||
9998ddfcc9 | |||
12ed54c9fd | |||
612c024b1f | |||
12ad545fe8 | |||
6d0f6a61d7 | |||
e3bcad6d3c | |||
f7c372a85c | |||
bb277a4a76 | |||
52b78a583e | |||
20ab36191b | |||
dbfb80e660 | |||
421f4471de | |||
04ea2b2dc9 | |||
93a2404343 | |||
149cda9a3b | |||
b9465b2a20 | |||
ab07f2ecbe | |||
c70c147afe | |||
8db52212ab | |||
d021a3995e | |||
1ea347ed21 | |||
0725e54271 | |||
3b6aca2451 | |||
249e44532f | |||
d3af3663ec | |||
3a1a21e498 | |||
e5bfa99b92 | |||
bf18154fcf | |||
5efc9e383b | |||
6505119d3b | |||
600f97de29 | |||
a1c21d2143 | |||
39066fb5f2 | |||
8fd99052fb | |||
4e671eb512 | |||
2677c4a4ec | |||
e19890e27a | |||
28556f277b | |||
50e08f198c | |||
7639b60b15 | |||
765a9686d8 | |||
ff443aa7c4 | |||
28fc328cb3 | |||
083f121683 | |||
2f57d3be84 | |||
7b47dadede | |||
8ad5485347 | |||
8df78e45d9 | |||
39cef5e61d | |||
5552f9d834 | |||
d13795696d | |||
f640f17fa6 | |||
494a32d45d | |||
8040a455be | |||
f091cff7c9 | |||
401ef7336b | |||
18134519be | |||
7980f14efb | |||
40d6a41305 | |||
9cfd835171 | |||
95a9f592eb | |||
61411fd0f3 | |||
a84eb16392 | |||
3355a6f472 | |||
071a8ea9f7 | |||
ea3777d28b | |||
3346b97ee7 | |||
2b834a75a8 | |||
21df53d547 | |||
9143c1c2c1 | |||
83cab7563d | |||
b05fbe7f6e | |||
e6a57738f4 | |||
cc6e35165a | |||
7791ddf76e | |||
4742cf0f3f | |||
8858970491 | |||
f7d18bfead | |||
0ce1b7fa15 | |||
4633592711 | |||
54697ab6b1 | |||
1eed844b9a | |||
dd89fe2463 | |||
9c66db97ff | |||
fea6afdfe4 | |||
6ec2e742ef | |||
3f80b054fc | |||
96d81873d8 | |||
c429ae9920 | |||
6b4e769f48 | |||
b67a9de0e9 | |||
ac9f65a068 | |||
7e8ebb2af2 | |||
f53fe2f881 | |||
6fdd88527a | |||
b6f431e14d | |||
23dee01f06 | |||
5532f91423 | |||
c849d5f3e5 | |||
3f3fd05cb1 | |||
a5bedf9a5b | |||
9d9dd62f00 | |||
a466578467 | |||
3a9420fedf | |||
8ac19a83b2 | |||
9f0b2f7074 | |||
e02ac43c07 | |||
97f76fb62c | |||
3508fd97ec | |||
90f6f68693 | |||
733775d3b9 | |||
f3aa6a9203 | |||
ffdcc7baca | |||
a1e20f4c9a | |||
ccffdad4c0 | |||
2fb5845501 | |||
ddd84a1765 | |||
048ae6a58c | |||
fafa54e4c9 | |||
60dbb32e9e | |||
52b07fd9cb | |||
f6a13aed86 | |||
2da3ba0262 | |||
e08c7cbbfb | |||
a6de5d8a21 | |||
8ec5bc05e0 | |||
6e0c12afb3 | |||
466e880bfc | |||
00a20b7cfc | |||
f27c95191b | |||
c140d2c37c | |||
3a42f2a2f0 | |||
00efedaa09 | |||
72e3d229dc | |||
b12d6ef484 | |||
8ee6fd3e67 | |||
808c5b00a0 | |||
4de6b51e76 | |||
0a8feca6ab | |||
4ca81df401 | |||
8b463b3bb6 | |||
17d696e33a | |||
2f59867db6 | |||
90f3da74cf | |||
28d8659cb5 | |||
5d1740a2ef | |||
7aa44568d8 | |||
bf1f702e5a | |||
78ad3e340a | |||
63a965beab | |||
815354e06f | |||
1cff104bae | |||
4805efad2e | |||
12e2ae9e91 | |||
c07b5cf709 | |||
0684738ec2 | |||
f2b50478bf | |||
fc71ebdfef | |||
10114bb12d | |||
6da3efdacc | |||
7cd8864fb9 | |||
a9c69664c7 | |||
50569224c3 | |||
e6d4741955 | |||
4d7387524c | |||
877aa325bb | |||
eb797d8986 | |||
fcb542471b | |||
5fe4405d76 | |||
baf0f17bd6 | |||
8e911698a5 | |||
0eb36be053 | |||
79dffc873a | |||
26ee12759c | |||
2e00634bc4 | |||
d63e6bf6b1 | |||
a95366e54e | |||
1c376abeb6 | |||
353d888abd | |||
b6bd532295 | |||
c5b004166d | |||
2f43600daf | |||
b39c7ce323 | |||
5b00279996 | |||
53b24965aa | |||
edce1bef92 | |||
e0d54d3af3 | |||
d1d1e01aff | |||
980bc597e2 | |||
a05c5edd49 | |||
985452f5f4 | |||
482674b3b3 | |||
fcbfed9068 | |||
a9167b4809 | |||
5b28eb0d00 | |||
f1b176670c | |||
11ce9a5206 | |||
8b667b8d4c | |||
a601a82a37 | |||
dcf3767a05 | |||
a9278009f8 | |||
5220f9e07c | |||
0b88064ca2 | |||
2233ccb968 | |||
311fde01a1 | |||
146d0ad9e5 | |||
385ad92331 | |||
571f8b526b | |||
7688aa99f6 | |||
4994bca34c | |||
1a3603dbfb | |||
aedfca377f | |||
7926f6c189 | |||
0303a9f553 | |||
e9a007d446 | |||
e382dbff84 | |||
e08be3d7a4 | |||
03c4190c2c | |||
12c1f82efe | |||
b1711ae293 | |||
a367951d07 | |||
c55f82c425 | |||
2dab11e8b3 | |||
d1044d262e | |||
010fde6258 | |||
8d83219bb6 | |||
a710483918 | |||
4f8ecf631b | |||
cc453dc24e | |||
60abe4857b | |||
dc942bc2e4 | |||
90497036a6 | |||
fe2032a3d4 | |||
877dcb462f | |||
4a3b7d71fe | |||
0e1bfb6524 | |||
e68bc50e6e | |||
a6a8012b39 | |||
e9e42011cd | |||
85f686dede | |||
0f6f79ebc6 | |||
9a6c92222c | |||
33f87523e0 | |||
a53818754a | |||
6c2f335a31 | |||
ff80f76855 | |||
6f0f3ccca7 | |||
eb9cc767c6 | |||
410080a8a3 | |||
d5b6225a90 | |||
a777842f9d | |||
62306133c8 | |||
a7f6224fb2 | |||
e97c432a64 | |||
0411153832 | |||
f9a0d1b388 | |||
bf5bcea607 | |||
f969c866a7 | |||
07261232ff | |||
2018f41368 | |||
bfa0edeb09 | |||
3d91c84966 | |||
f91fd5921f | |||
36157bb8db | |||
a38abeb4c2 | |||
675192b86f | |||
bc1132146f | |||
d850f37904 | |||
f15fdb921e | |||
7b43551148 | |||
ad356d2759 | |||
5f594a822f | |||
89df3c48e0 | |||
3436a1584c | |||
d44b0d50d8 | |||
1bd94aca7c | |||
f264e4d0f7 | |||
d8252141fe | |||
d9716a1cf7 | |||
e9bd27bc55 | |||
0a69851463 | |||
5e7c5aa620 | |||
f6996a1d98 | |||
e9ea4845be | |||
d961721b33 | |||
bb8c29f4a2 | |||
e10c20fa42 | |||
94274733f4 | |||
42f723813a | |||
4c75b91ce9 | |||
3dd6faa620 | |||
9a1313fe89 | |||
fe43525dad | |||
92da93a160 | |||
cf0c2c7691 | |||
e9aecfac1c | |||
12c8cb93f6 | |||
f9c97a673e | |||
ca8f331eec | |||
9e11774a1b | |||
257c8bde99 | |||
0bdbb1b24a | |||
bd1aa7b49e | |||
5de3dc802f | |||
f25ecd0743 | |||
cdf3a6fb40 | |||
f9c5db8df7 | |||
7d05d69707 | |||
08a3538d8e | |||
6b38a3637f | |||
7d116d1ce9 | |||
73267ac4e5 | |||
efe7d594b0 | |||
b7a4ca9c3b | |||
810fd7e7b8 | |||
22bd13a253 | |||
5f22950721 | |||
31fdf08c27 | |||
2d12f6e54c | |||
f7c02f4679 | |||
3fcfc29e3f | |||
817356f2a8 | |||
8fbaec3567 | |||
3f1eda60eb | |||
0d5e9ce9d8 | |||
019ae24c7d | |||
4dd84ded54 | |||
5232c055b1 | |||
06d3f3c34b | |||
2aca988c0b | |||
fc27e44471 | |||
60f312446e | |||
807605c0cc | |||
1aa592b1b9 | |||
763fa62eca | |||
40ac08836d | |||
6bdcee1d1b | |||
0ea79775c5 | |||
696b5daf5c | |||
e136f4e987 | |||
41308fea13 | |||
0e14b2d2e3 | |||
c9b66bf77b | |||
4168d1a296 | |||
51d172b8fc | |||
e02e54db2c | |||
305dd84769 | |||
985ea30d36 | |||
cc904ee211 | |||
8ceb38963e | |||
59ca9df663 | |||
0689489985 | |||
3015b05c77 | |||
f299e49966 | |||
0186450221 | |||
974eb510ef | |||
1fad9a666e | |||
b6cf1ab951 | |||
d979ef3b40 | |||
4a320d3031 | |||
fbfdc6a383 | |||
4dfce582c8 | |||
ee048968cc | |||
fe54e892cc | |||
5fab6e2714 | |||
8e80df30b9 | |||
b9e7b9e1e3 | |||
bb88053ae3 | |||
0611b94c01 | |||
3da0bb38df | |||
c57c7f2aa7 | |||
a05abd0eea | |||
c95e765456 | |||
9d034ab48d | |||
796e000826 | |||
60a92fb22b | |||
ddbae91840 | |||
ded155a6af | |||
59cc0d3211 | |||
4b06baab3f | |||
ef16dac4f4 | |||
b8934c68f2 | |||
e5fae3af64 | |||
34a92ab448 | |||
6c85ad3188 | |||
9f0e55b7b8 | |||
612a2f90ac | |||
c797ed9c25 | |||
5dc82d8176 | |||
802e461792 | |||
b9e702086a | |||
9f591c4d87 | |||
55220c147d | |||
2ea5b1c0bd | |||
ed72d60951 | |||
5f6d177df9 | |||
b3e15d6729 | |||
b26a9f8dcf | |||
f3a822b4b2 | |||
cee091fa58 | |||
84ebf8e6c3 | |||
2a0b45dc20 | |||
00955d2e4f | |||
044442b0d7 | |||
99290d646e | |||
52007785af | |||
9d3b32a841 | |||
0b939b1cd6 | |||
d63adc7a6b | |||
026a221e5e | |||
f1ac646518 | |||
8b3cf8c38c | |||
89e2129ca4 | |||
d9999f8dd9 | |||
0b963ec3b8 | |||
369ec9c30b | |||
c19a2e71b5 | |||
6085f69c22 | |||
8cb8d3514a | |||
55005b57c6 | |||
80cdaaeb1c | |||
deccfd7cc9 | |||
0f4c2e64f4 | |||
b8b5d18662 | |||
5ee5698347 | |||
97b254ee7b | |||
ac40a40ec0 | |||
b5b96506ae | |||
548fe3c864 | |||
97e976a184 | |||
5de6617d10 | |||
bcd6110578 | |||
ba0ca78696 | |||
22ba53ad4c | |||
81304f50d1 | |||
3c22372f49 | |||
7584671312 | |||
7296c9e744 | |||
c63a8982e4 | |||
8d35dc1bb0 | |||
0fedfcf709 | |||
6c2eb882bb | |||
c9eb27de11 | |||
dadd8c122f | |||
59560d96ba | |||
864c9afd93 | |||
b4f07f51ae | |||
e9b153095c | |||
7968c1efcf | |||
87648a742c | |||
cdb86b741c | |||
15e8d7c053 | |||
cbe9c3ac50 | |||
4d7bdc2ed9 | |||
d10c707f12 | |||
ac512b2eab | |||
fdf6a59c4c | |||
4b9a6a6735 | |||
49cc8a267c | |||
68cb57aea6 | |||
9d7fd55e4c | |||
195c62f80b | |||
1fd222abea | |||
ac40e13e33 | |||
53ab822dbc | |||
0c9c292291 | |||
573dd753a7 | |||
79b5b3a1f6 | |||
52e8fe576e | |||
0d34d2d92e | |||
b389ac6347 | |||
534c601068 | |||
424436579b | |||
a716360faa | |||
af485c678d | |||
84e298e7ee | |||
753287d9d1 | |||
21bb8f9016 | |||
dc136daeab | |||
e8bc7952db | |||
06418655c0 | |||
c99b2940c6 | |||
e67f5f80e1 | |||
3691d79a4a | |||
8108eca2fa | |||
4f48c8fb80 | |||
20ba081308 | |||
2119ae769b | |||
c618ca7539 | |||
8b11140be2 | |||
bebfec7755 | |||
124aac4888 | |||
b3bfd063d8 | |||
c92cab5e5b | |||
8c613195f3 | |||
41f941728e | |||
ecf1542d95 | |||
06b2bbba25 | |||
0494fdeabd | |||
226206b100 | |||
02f80bc616 | |||
3189c9251a | |||
ae43137906 | |||
50bee30799 | |||
38484a3063 | |||
919327ed08 | |||
c00c5fa02d | |||
80f09ac10b | |||
ee721ffbec | |||
323f91dd68 | |||
810ccb40d7 | |||
5242f7d55c | |||
d293ae516c | |||
3fb563f9c8 | |||
1dd1c65341 | |||
e593327fea | |||
64e0aeeb18 | |||
05816abc12 | |||
ce306aef07 | |||
373c850f35 | |||
a0e00b8eff | |||
a954c69458 | |||
a0e034bd55 | |||
1a1c1f26d9 | |||
114c429aed | |||
40251a76f6 | |||
a102b479e6 | |||
5b5f5ea203 | |||
40a8e581f1 | |||
1b988e7135 | |||
9433c7aedc | |||
479dfed987 | |||
1866033128 | |||
844b9ab2ec | |||
e6713d6ce2 | |||
069ce73c07 | |||
6dda6a5513 | |||
329def42ac | |||
c5137b5fad | |||
ab05ccb846 |
@ -7,6 +7,7 @@ indent_style = space
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
max_line_length = off
|
max_line_length = off
|
||||||
|
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: dolanmiu
|
||||||
|
patreon: dolanmiu
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
104
.github/workflows/default.yml
vendored
Normal file
104
.github/workflows/default.yml
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
name: Default
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
- name: Archive Production Artifact
|
||||||
|
uses: actions/upload-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Test
|
||||||
|
run: npm run test.coverage
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
prettier:
|
||||||
|
name: Prettier
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Prettier
|
||||||
|
run: npm run style
|
||||||
|
demos:
|
||||||
|
name: Run Demos
|
||||||
|
needs: [build]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Download Artifact
|
||||||
|
uses: actions/download-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
- name: Run demos
|
||||||
|
run: |
|
||||||
|
npm run ts-node -- ./demo/1-basic.ts
|
||||||
|
npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||||
|
npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||||
|
npm run ts-node -- ./demo/4-basic-table.ts
|
||||||
|
npm run ts-node -- ./demo/5-images.ts
|
||||||
|
npm run ts-node -- ./demo/6-page-borders.ts
|
||||||
|
npm run ts-node -- ./demo/7-landscape.ts
|
||||||
|
npm run ts-node -- ./demo/8-header-footer.ts
|
||||||
|
npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||||
|
npm run ts-node -- ./demo/10-my-cv.ts
|
||||||
|
npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||||
|
npm run ts-node -- ./demo/12-scaling-images.ts
|
||||||
|
npm run ts-node -- ./demo/13-xml-styles.ts
|
||||||
|
npm run ts-node -- ./demo/14-page-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/15-page-break-before.ts
|
||||||
|
npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||||
|
npm run ts-node -- ./demo/17-footnotes.ts
|
||||||
|
npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||||
|
npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
|
npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
|
npm run ts-node -- ./demo/21-bookmarks.ts
|
||||||
|
npm run ts-node -- ./demo/22-right-to-left-text.ts
|
||||||
|
npm run ts-node -- ./demo/23-base64-images.ts
|
||||||
|
npm run ts-node -- ./demo/24-images-to-table-cell.ts
|
||||||
|
npm run ts-node -- ./demo/26-paragraph-borders.ts
|
||||||
|
npm run ts-node -- ./demo/27-declaritive-styles-3.ts
|
||||||
|
npm run ts-node -- ./demo/28-table-of-contents.ts
|
||||||
|
npm run ts-node -- ./demo/29-numbered-lists.ts
|
||||||
|
npm run ts-node -- ./demo/30-template-document.ts
|
||||||
|
npm run ts-node -- ./demo/31-tables.ts
|
||||||
|
npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts
|
||||||
|
npm run ts-node -- ./demo/33-sequential-captions.ts
|
||||||
|
npm run ts-node -- ./demo/34-floating-tables.ts
|
18
.gitignore
vendored
18
.gitignore
vendored
@ -36,6 +36,10 @@ node_modules
|
|||||||
build
|
build
|
||||||
build-tests
|
build-tests
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
docs/api/
|
||||||
|
docs/.nojekyll
|
||||||
|
|
||||||
# VSCode
|
# VSCode
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
@ -44,5 +48,17 @@ build-tests
|
|||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
.history
|
.history
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
.idea
|
||||||
|
|
||||||
# Lock files
|
# Lock files
|
||||||
package-lock.json
|
yarn.lock
|
||||||
|
|
||||||
|
# Documents
|
||||||
|
My Document.docx
|
||||||
|
|
||||||
|
# Temporary folder
|
||||||
|
tmp
|
||||||
|
|
||||||
|
# nyc
|
||||||
|
.nyc_output
|
||||||
|
26
.nycrc
Normal file
26
.nycrc
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"check-coverage": true,
|
||||||
|
"lines": 96.81,
|
||||||
|
"functions": 93.80,
|
||||||
|
"branches": 92.63,
|
||||||
|
"statements": 96.80,
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/import-dotx/import-dotx.ts"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"lcov",
|
||||||
|
"text",
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"extension": [
|
||||||
|
".ts"
|
||||||
|
],
|
||||||
|
"cache": true,
|
||||||
|
"all": true,
|
||||||
|
"instrument": false,
|
||||||
|
"sourceMap": true
|
||||||
|
}
|
5
.prettierrc.yml
Normal file
5
.prettierrc.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
trailingComma: all
|
||||||
|
printWidth: 140
|
||||||
|
tabWidth: 4
|
||||||
|
arrowParens: always
|
||||||
|
bracketSpacing: true
|
66
.travis.yml
66
.travis.yml
@ -1,25 +1,63 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "stable"
|
- 10
|
||||||
install:
|
install:
|
||||||
- npm install
|
- npm install
|
||||||
|
- npm install -g codecov
|
||||||
script:
|
script:
|
||||||
- npm run lint
|
- npm run lint
|
||||||
- npm test
|
- npm run test.coverage
|
||||||
- npm run style
|
- npm run style
|
||||||
- npm run build
|
- npm run build
|
||||||
- node ./demo/demo1.js
|
- npm run ts-node -- ./demo/1-basic.ts
|
||||||
- node ./demo/demo2.js
|
# - npm run e2e "My Document.docx"
|
||||||
- node ./demo/demo3.js
|
- npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||||
- node ./demo/demo4.js
|
- npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||||
- node ./demo/demo5.js
|
- npm run ts-node -- ./demo/4-basic-table.ts
|
||||||
- node ./demo/demo6.js
|
- npm run ts-node -- ./demo/5-images.ts
|
||||||
- node ./demo/demo7.js
|
- npm run ts-node -- ./demo/6-page-borders.ts
|
||||||
|
- npm run ts-node -- ./demo/7-landscape.ts
|
||||||
|
- npm run ts-node -- ./demo/8-header-footer.ts
|
||||||
|
- npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||||
|
- npm run ts-node -- ./demo/10-my-cv.ts
|
||||||
|
# - npm run e2e "My Document.docx"
|
||||||
|
- npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||||
|
- npm run ts-node -- ./demo/12-scaling-images.ts
|
||||||
|
- npm run ts-node -- ./demo/13-xml-styles.ts
|
||||||
|
- npm run ts-node -- ./demo/14-page-numbers.ts
|
||||||
|
- npm run ts-node -- ./demo/15-page-break-before.ts
|
||||||
|
- npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||||
|
- npm run ts-node -- ./demo/17-footnotes.ts
|
||||||
|
- npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||||
|
- npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
|
- npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
|
- npm run ts-node -- ./demo/21-bookmarks.ts
|
||||||
|
- npm run ts-node -- ./demo/22-right-to-left-text.ts
|
||||||
|
- npm run ts-node -- ./demo/23-base64-images.ts
|
||||||
|
- npm run ts-node -- ./demo/24-images-to-table-cell.ts
|
||||||
|
# - npm run ts-node -- ./demo/demo25.ts
|
||||||
|
- npm run ts-node -- ./demo/26-paragraph-borders.ts
|
||||||
|
- npm run ts-node -- ./demo/27-declaritive-styles-3.ts
|
||||||
|
- npm run ts-node -- ./demo/28-table-of-contents.ts
|
||||||
|
- npm run ts-node -- ./demo/29-numbered-lists.ts
|
||||||
|
- npm run ts-node -- ./demo/30-template-document.ts
|
||||||
|
- npm run ts-node -- ./demo/31-tables.ts
|
||||||
|
- npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts
|
||||||
|
# - npm run e2e "My Document.docx" // Need to fix
|
||||||
|
- npm run ts-node -- ./demo/33-sequential-captions.ts
|
||||||
|
- npm run ts-node -- ./demo/34-floating-tables.ts
|
||||||
after_failure:
|
after_failure:
|
||||||
- "cat /home/travis/builds/dolanmiu/docx/npm-debug.log"
|
- "cat /home/travis/builds/dolanmiu/docx/npm-debug.log"
|
||||||
after_success:
|
after_success:
|
||||||
- bash ./deploy-docs.sh
|
- npm run typedoc
|
||||||
env:
|
- echo "docx.js.org" > docs/.nojekyll
|
||||||
global:
|
- echo "docx.js.org" > docs/CNAME
|
||||||
- ENCRYPTION_LABEL: "ad385fa3b525"
|
- codecov
|
||||||
|
deploy:
|
||||||
|
provider: pages
|
||||||
|
skip-cleanup: true
|
||||||
|
github-token: $GITHUB_TOKEN
|
||||||
|
keep-history: true
|
||||||
|
local-dir: docs
|
||||||
|
on:
|
||||||
|
branch: master
|
||||||
|
24
.vscode/tasks.json
vendored
Normal file
24
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "typescript",
|
||||||
|
"tsconfig": "tsconfig.json",
|
||||||
|
"option": "watch",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$tsc-watch"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "ts-node",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
127
README.md
127
README.md
@ -1,99 +1,122 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="clippy the assistant" src="http://i60.tinypic.com/339pvtt.png">
|
<img alt="clippy the assistant" src="https://i.imgur.com/37uBGhO.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
Generate .docx files with JS/TS very easily, written in TS.
|
Easily generate .docx files with JS/TS. Works for Node and on the Browser.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
-----
|
---
|
||||||
|
|
||||||
[![NPM version][npm-image]][npm-url]
|
[![NPM version][npm-image]][npm-url]
|
||||||
|
[![Downloads per month][downloads-image]][downloads-url]
|
||||||
[![Build Status][travis-image]][travis-url]
|
[![Build Status][travis-image]][travis-url]
|
||||||
[![Dependency Status][gemnasium-image]][gemnasium-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]
|
||||||
[![code style: prettier][prettier-image]][prettier-url]
|
[![PRs Welcome][pr-image]][pr-url]
|
||||||
|
[![codecov][codecov-image]][codecov-url]
|
||||||
|
|
||||||
[](https://nodei.co/npm/docx/)
|
<p align="center">
|
||||||
|
<img src="https://i.imgur.com/TCH0YzD.png" alt="drawing" width="800"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
# docx
|
# Demo
|
||||||
|
|
||||||
## Install
|
## Browser
|
||||||
|
|
||||||
```sh
|
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
||||||
$ npm install --save docx
|
|
||||||
```
|
|
||||||
|
|
||||||
## Demo
|
* https://codepen.io/dolanmiu/pen/RwNeObg
|
||||||
|
* https://jsfiddle.net/dolanmiu/kqxrj35u/1/
|
||||||
|
|
||||||
```sh
|
Here is an example of `docx` working in `Angular`:
|
||||||
$ npm run demo
|
|
||||||
```
|
|
||||||
|
|
||||||
will run the demo selector app in the `demo` folder. It will prompt you to select a demo number, which will run a demo from that folder.
|
* https://stackblitz.com/edit/angular-afvxtz
|
||||||
|
|
||||||
## Guide
|
Here is an example of `docx` working in `React`:
|
||||||
|
|
||||||
Please refer to [the Wiki](https://github.com/dolanmiu/docx/wiki) for details on how to use this library, examples and much more!
|
* https://stackblitz.com/edit/react-ts-qq25sp
|
||||||
|
* https://stackblitz.com/edit/react-ts-qdqu7z (adding images to Word Document)
|
||||||
|
|
||||||
Full documentation can be found here: [http://dolanmiu.github.io/docx](http://dolanmiu.github.io/docx)
|
Here is an example of `docx` working in `Vue.js`:
|
||||||
|
|
||||||
## Simple Usage
|
* https://stackblitz.com/edit/vuejs-docx
|
||||||
|
|
||||||
```js
|
## Node
|
||||||
// Used to create docx files
|
|
||||||
var docx = require('docx');
|
|
||||||
|
|
||||||
// Create document
|
Press `endpoint` on the `RunKit` website:
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
// Add some content in the document
|

|
||||||
var paragraph = new docx.Paragraph("Some cool text here.");
|
|
||||||
// Add more text into the paragraph if you wish
|
|
||||||
paragraph.addRun(new docx.TextRun('Lorem Ipsum Foo Bar'));
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
// Used to export the file into a .docx file
|
* https://runkit.com/dolanmiu/docx-demo1 - Simple paragraph and text
|
||||||
var exporter = new docx.LocalPacker(doc);
|
* https://runkit.com/dolanmiu/docx-demo2 - Advanced Paragraphs and text
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo3 - Bullet points
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo4 - Simple table
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo5 - Images
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo6 - Margins
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo7 - Landscape
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
||||||
|
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||||
|
|
||||||
// Or use the express packer to make the file downloadable.
|
More [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
// res is express' Response object
|
|
||||||
var exporter = new docx.ExpressPacker(doc, res);
|
|
||||||
|
|
||||||
exporter.pack('My First Document');
|
# How to use & Documentation
|
||||||
// If you want to export it as a .pdf file instead
|
|
||||||
exporter.packPdf('My First Document');
|
|
||||||
|
|
||||||
// done! A file called 'My First Document.docx'
|
Please refer to the [documentation at https://docx.js.org/](https://docx.js.org/) for details on how to use this library, examples and much more!
|
||||||
// will be in your file system if you used LocalPacker
|
|
||||||
// Or it will start downloading if you are using Express
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
# Examples
|
||||||
Check [the Wiki](https://github.com/dolanmiu/docx/wiki/Examples) for examples.
|
|
||||||
|
Check the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
Read the contribution guidelines [here](https://github.com/dolanmiu/docx/wiki/Contributing-Guidelines).
|
Read the contribution guidelines [here](https://docx.js.org/#/contribution-guidelines).
|
||||||
|
|
||||||
-----
|
# Used by
|
||||||
|
|
||||||
|
[<img src="https://i.imgur.com/zy5qWmI.png" alt="drawing" height="50"/>](https://hfour.com/)
|
||||||
|
[<img src="https://i.imgur.com/OYP5tgS.png" alt="drawing" height="50"/>](https://fuzzproductions.com/)
|
||||||
|
[<img src="https://i.imgur.com/zUDMfZ3.png" alt="drawing" height="50"/>](https://www.mettzer.com/)
|
||||||
|
[<img src="https://i.imgur.com/wtNB1uq.png" alt="drawing" height="50"/>](https://www.wisedoc.net/)
|
||||||
|
[<img src="https://i.imgur.com/suiH2zc.png" alt="drawing" height="50"/>](https://www.dabblewriter.com/)
|
||||||
|
[<img src="https://i.imgur.com/1LjuK2M.png" alt="drawing" height="50"/>](https://turbopatent.com/)
|
||||||
|
[<img src="https://i.imgur.com/dHMg0wF.gif" alt="drawing" height="50"/>](http://www.madisoncres.com/)
|
||||||
|
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
||||||
|
[<img src="https://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/cmykN7c.png" alt="drawing"/>](https://www.arity.co/)
|
||||||
|
|
||||||
|
|
||||||
|
...and many more!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
[![patreon][patreon-image]][patreon-url]
|
||||||
|
[![browserstack][browserstack-image]][browserstack-url]
|
||||||
|
|
||||||
Made with 💖
|
Made with 💖
|
||||||
|
|
||||||
Huge thanks to [@felipeochoa](https://github.com/felipeochoa) for awesome contributions to this project
|
|
||||||
|
|
||||||
[npm-image]: https://badge.fury.io/js/docx.svg
|
[npm-image]: https://badge.fury.io/js/docx.svg
|
||||||
[npm-url]: https://npmjs.org/package/docx
|
[npm-url]: https://npmjs.org/package/docx
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/docx.svg
|
||||||
|
[downloads-url]: https://npmjs.org/package/docx
|
||||||
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
||||||
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
||||||
|
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
||||||
|
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
||||||
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
[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
|
||||||
[gitter-url]: https://gitter.im/docx-lib/Lobby
|
[gitter-url]: https://gitter.im/docx-lib/Lobby
|
||||||
[gemnasium-image]: https://gemnasium.com/badges/github.com/dolanmiu/docx.svg
|
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
||||||
[gemnasium-url]: https://gemnasium.com/github.com/dolanmiu/docx
|
[pr-url]: http://makeapullrequest.com
|
||||||
[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
|
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg
|
||||||
[prettier-url]: https://github.com/prettier/prettier
|
[codecov-url]: https://codecov.io/gh/dolanmiu/docx
|
||||||
|
[patreon-image]: https://user-images.githubusercontent.com/2917613/51251459-4e880480-1991-11e9-92bf-38b96675a9e2.png
|
||||||
|
[patreon-url]: https://www.patreon.com/dolanmiu
|
||||||
|
[browserstack-image]: https://user-images.githubusercontent.com/2917613/54233552-128e9d00-4505-11e9-88fb-025a4e04007c.png
|
||||||
|
[browserstack-url]: https://www.browserstack.com
|
||||||
|
29
demo/1-basic.ts
Normal file
29
demo/1-basic.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
347
demo/10-my-cv.ts
Normal file
347
demo/10-my-cv.ts
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
// Generate a CV
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||||
|
|
||||||
|
// tslint:disable:no-shadowed-variable
|
||||||
|
|
||||||
|
const PHONE_NUMBER = "07534563401";
|
||||||
|
const PROFILE_URL = "https://www.linkedin.com/in/dolan1";
|
||||||
|
const EMAIL = "docx@com";
|
||||||
|
|
||||||
|
const experiences = [
|
||||||
|
{
|
||||||
|
isCurrent: true,
|
||||||
|
summary: "Full-stack developer working with Angular and Java. Working for the iShares platform",
|
||||||
|
title: "Associate Software Developer",
|
||||||
|
startDate: {
|
||||||
|
month: 11,
|
||||||
|
year: 2017,
|
||||||
|
},
|
||||||
|
company: {
|
||||||
|
name: "BlackRock",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCurrent: false,
|
||||||
|
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.",
|
||||||
|
title: "Software Developer",
|
||||||
|
endDate: {
|
||||||
|
month: 11,
|
||||||
|
year: 2017,
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
month: 10,
|
||||||
|
year: 2016,
|
||||||
|
},
|
||||||
|
company: {
|
||||||
|
name: "Torch Markets",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCurrent: false,
|
||||||
|
summary:
|
||||||
|
"Used ASP.NET MVC 5 to produce a diversity data collection tool for the future of British television.\n\nUsed AngularJS and C# best practices. Technologies used include JavaScript, ASP.NET MVC 5, SQL, Oracle, SASS, Bootstrap, Grunt.",
|
||||||
|
title: "Software Developer",
|
||||||
|
endDate: {
|
||||||
|
month: 10,
|
||||||
|
year: 2016,
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
month: 3,
|
||||||
|
year: 2015,
|
||||||
|
},
|
||||||
|
company: {
|
||||||
|
name: "Soundmouse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isCurrent: false,
|
||||||
|
summary:
|
||||||
|
"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",
|
||||||
|
endDate: {
|
||||||
|
month: 10,
|
||||||
|
year: 2014,
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
month: 3,
|
||||||
|
year: 2013,
|
||||||
|
},
|
||||||
|
company: {
|
||||||
|
name: "Soundmouse",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const education = [
|
||||||
|
{
|
||||||
|
degree: "Master of Science (MSc)",
|
||||||
|
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.",
|
||||||
|
schoolName: "University College London",
|
||||||
|
startDate: {
|
||||||
|
year: 2012,
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
year: 2013,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
degree: "Bachelor of Engineering (BEng)",
|
||||||
|
fieldOfStudy: "Material Science and Engineering",
|
||||||
|
notes:
|
||||||
|
"Exam Results: 2:1, Dissertation: 1st Class with Distinction\n\nRelevant courses: C Programming, Mathematics and Business for Engineers.",
|
||||||
|
schoolName: "Imperial College London",
|
||||||
|
startDate: {
|
||||||
|
year: 2009,
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
year: 2012,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const skills = [
|
||||||
|
{
|
||||||
|
name: "Angular",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "TypeScript",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "JavaScript",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "NodeJS",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const achievements = [
|
||||||
|
{
|
||||||
|
issuer: "Oracle",
|
||||||
|
name: "Oracle Certified Expert",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
class DocumentCreator {
|
||||||
|
// tslint:disable-next-line: typedef
|
||||||
|
public create([experiences, educations, skills, achivements]): Document {
|
||||||
|
const document = new Document();
|
||||||
|
|
||||||
|
document.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Dolan Miu",
|
||||||
|
heading: HeadingLevel.TITLE,
|
||||||
|
}),
|
||||||
|
this.createContactInfo(PHONE_NUMBER, PROFILE_URL, EMAIL),
|
||||||
|
this.createHeading("Education"),
|
||||||
|
...educations
|
||||||
|
.map((education) => {
|
||||||
|
const arr: Paragraph[] = [];
|
||||||
|
arr.push(
|
||||||
|
this.createInstitutionHeader(education.schoolName, `${education.startDate.year} - ${education.endDate.year}`),
|
||||||
|
);
|
||||||
|
arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
|
||||||
|
|
||||||
|
const bulletPoints = this.splitParagraphIntoBullets(education.notes);
|
||||||
|
bulletPoints.forEach((bulletPoint) => {
|
||||||
|
arr.push(this.createBullet(bulletPoint));
|
||||||
|
});
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
})
|
||||||
|
.reduce((prev, curr) => prev.concat(curr), []),
|
||||||
|
this.createHeading("Experience"),
|
||||||
|
...experiences
|
||||||
|
.map((position) => {
|
||||||
|
const arr: Paragraph[] = [];
|
||||||
|
|
||||||
|
arr.push(
|
||||||
|
this.createInstitutionHeader(
|
||||||
|
position.company.name,
|
||||||
|
this.createPositionDateText(position.startDate, position.endDate, position.isCurrent),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
arr.push(this.createRoleText(position.title));
|
||||||
|
|
||||||
|
const bulletPoints = this.splitParagraphIntoBullets(position.summary);
|
||||||
|
|
||||||
|
bulletPoints.forEach((bulletPoint) => {
|
||||||
|
arr.push(this.createBullet(bulletPoint));
|
||||||
|
});
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
})
|
||||||
|
.reduce((prev, curr) => prev.concat(curr), []),
|
||||||
|
this.createHeading("Skills, Achievements and Interests"),
|
||||||
|
this.createSubHeading("Skills"),
|
||||||
|
this.createSkillList(skills),
|
||||||
|
this.createSubHeading("Achievements"),
|
||||||
|
...this.createAchivementsList(achivements),
|
||||||
|
this.createSubHeading("Interests"),
|
||||||
|
this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."),
|
||||||
|
this.createHeading("References"),
|
||||||
|
new Paragraph(
|
||||||
|
"Dr. Dean Mohamedally Director of Postgraduate Studies Department of Computer Science, University College London Malet Place, Bloomsbury, London WC1E d.mohamedally@ucl.ac.uk",
|
||||||
|
),
|
||||||
|
new Paragraph("More references upon request"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public createContactInfo(phoneNumber: string, profileUrl: string, email: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
children: [
|
||||||
|
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
|
||||||
|
new TextRun({
|
||||||
|
text: "Address: 58 Elm Avenue, Kent ME4 6ER, UK",
|
||||||
|
break: 1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public createHeading(text: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
thematicBreak: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public createSubHeading(text: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public createInstitutionHeader(institutionName: string, dateText: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: institutionName,
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: `\t${dateText}`,
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public createRoleText(roleText: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: roleText,
|
||||||
|
italics: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public createBullet(text: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
bullet: {
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
public createSkillList(skills: any[]): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
children: [new TextRun(skills.map((skill) => skill.name).join(", ") + ".")],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
public createAchivementsList(achivements: any[]): Paragraph[] {
|
||||||
|
return achivements.map(
|
||||||
|
(achievement) =>
|
||||||
|
new Paragraph({
|
||||||
|
text: achievement.name,
|
||||||
|
bullet: {
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public createInterests(interests: string): Paragraph {
|
||||||
|
return new Paragraph({
|
||||||
|
children: [new TextRun(interests)],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public splitParagraphIntoBullets(text: string): string[] {
|
||||||
|
return text.split("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
public createPositionDateText(startDate: any, endDate: any, isCurrent: boolean): string {
|
||||||
|
const startDateText = this.getMonthFromInt(startDate.month) + ". " + startDate.year;
|
||||||
|
const endDateText = isCurrent ? "Present" : `${this.getMonthFromInt(endDate.month)}. ${endDate.year}`;
|
||||||
|
|
||||||
|
return `${startDateText} - ${endDateText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getMonthFromInt(value: number): string {
|
||||||
|
switch (value) {
|
||||||
|
case 1:
|
||||||
|
return "Jan";
|
||||||
|
case 2:
|
||||||
|
return "Feb";
|
||||||
|
case 3:
|
||||||
|
return "Mar";
|
||||||
|
case 4:
|
||||||
|
return "Apr";
|
||||||
|
case 5:
|
||||||
|
return "May";
|
||||||
|
case 6:
|
||||||
|
return "Jun";
|
||||||
|
case 7:
|
||||||
|
return "Jul";
|
||||||
|
case 8:
|
||||||
|
return "Aug";
|
||||||
|
case 9:
|
||||||
|
return "Sept";
|
||||||
|
case 10:
|
||||||
|
return "Oct";
|
||||||
|
case 11:
|
||||||
|
return "Nov";
|
||||||
|
case 12:
|
||||||
|
return "Dec";
|
||||||
|
default:
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const documentCreator = new DocumentCreator();
|
||||||
|
|
||||||
|
const doc = documentCreator.create([experiences, education, skills, achievements]);
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
240
demo/11-declaritive-styles-2.ts
Normal file
240
demo/11-declaritive-styles-2.ts
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
// Setting styles with JavaScript configuration
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
convertInchesToTwip,
|
||||||
|
Document,
|
||||||
|
Footer,
|
||||||
|
HeadingLevel,
|
||||||
|
Media,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
TabStopPosition,
|
||||||
|
UnderlineType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
default: {
|
||||||
|
heading1: {
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 52,
|
||||||
|
bold: true,
|
||||||
|
color: "000000",
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.SINGLE,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
spacing: { line: 340 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
heading2: {
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 340 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
heading3: {
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
heading4: {
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.JUSTIFIED,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "normalPara",
|
||||||
|
name: "Normal Para",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
rightTabStop: TabStopPosition.MAX,
|
||||||
|
leftTabStop: 453.543307087,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "normalPara2",
|
||||||
|
name: "Normal Para2",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.JUSTIFIED,
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "aside",
|
||||||
|
name: "Aside",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "999999",
|
||||||
|
italics: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276 },
|
||||||
|
indent: { left: convertInchesToTwip(0.5) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "wellSpaced",
|
||||||
|
name: "Well Spaced",
|
||||||
|
basedOn: "Normal",
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 1.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 2.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 3.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 4.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
top: 700,
|
||||||
|
right: 700,
|
||||||
|
bottom: 700,
|
||||||
|
left: 700,
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "1",
|
||||||
|
style: "normalPara",
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph(image),
|
||||||
|
new Paragraph({
|
||||||
|
text: "HEADING",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Ref. :",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Date :",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "To,",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "The Superindenting Engineer,(O &M)",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Sub : ",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Ref. : ",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Sir,",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "BRIEF DESCRIPTION",
|
||||||
|
style: "normalPara",
|
||||||
|
}),
|
||||||
|
table,
|
||||||
|
new Paragraph(image1),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Test",
|
||||||
|
style: "normalPara2",
|
||||||
|
}),
|
||||||
|
new Paragraph(image2),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Test 2",
|
||||||
|
style: "normalPara2",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
19
demo/12-scaling-images.ts
Normal file
19
demo/12-scaling-images.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Scaling images
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Media, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 50, 50);
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 100, 100);
|
||||||
|
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 250, 250);
|
||||||
|
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 400, 400);
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [new Paragraph("Hello World"), new Paragraph(image), new Paragraph(image2), new Paragraph(image3), new Paragraph(image4)],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
32
demo/13-xml-styles.ts
Normal file
32
demo/13-xml-styles.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// This example shows 3 styles using XML styles
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
||||||
|
const doc = new Document({
|
||||||
|
title: "Title",
|
||||||
|
externalStyles: styles,
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Cool Heading Text",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: 'This is a custom named style from the template "MyFancyStyle"',
|
||||||
|
style: "MyFancyStyle",
|
||||||
|
}),
|
||||||
|
new Paragraph("Some normal text"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "MyFancyStyle again",
|
||||||
|
style: "MyFancyStyle",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
47
demo/14-page-numbers.ts
Normal file
47
demo/14-page-numbers.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Page numbers
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Header "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("First Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph("Second Page"),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
20
demo/15-page-break-before.ts
Normal file
20
demo/15-page-break-before.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Page break before example
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph("Hello World"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World on another page",
|
||||||
|
pageBreakBefore: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
124
demo/16-multiple-sections.ts
Normal file
124
demo/16-multiple-sections.ts
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
// Multiple sections and headers
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, PageNumber, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [new Paragraph("First Default Header on another page")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [new Paragraph("Footer on another page")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberStart: 1,
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [new Paragraph("Second Default Header on another page")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [new Paragraph("Footer on another page")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.LANDSCAPE,
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberStart: 1,
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("hello in landscape")],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.PORTRAIT,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN,
|
||||||
|
orientation: PageOrientation.PORTRAIT,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph(
|
||||||
|
"Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.PORTRAIT,
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
pageNumberStart: 25,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section."),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
55
demo/17-footnotes.ts
Normal file
55
demo/17-footnotes.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Footnotes
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, FootnoteReferenceRun, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
footnotes: [
|
||||||
|
new Paragraph("Foo"),
|
||||||
|
new Paragraph("Test"),
|
||||||
|
new Paragraph("My amazing reference"),
|
||||||
|
new Paragraph("Foo1"),
|
||||||
|
new Paragraph("Test1"),
|
||||||
|
new Paragraph("My amazing reference1"),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Hello", new FootnoteReferenceRun(1)],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [" World!", new FootnoteReferenceRun(2)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World"), new FootnoteReferenceRun(3)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Hello", new FootnoteReferenceRun(4)],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [" World!", new FootnoteReferenceRun(5)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
22
demo/18-image-from-buffer.ts
Normal file
22
demo/18-image-from-buffer.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Insert image from a buffer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Media, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
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 image = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [image],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
28
demo/19-export-to-base64.ts
Normal file
28
demo/19-export-to-base64.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Export to base64 string - Useful in a browser environment.
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tBar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBase64String(doc).then((str) => {
|
||||||
|
fs.writeFileSync("My Document.docx", str);
|
||||||
|
});
|
190
demo/2-declaritive-styles.ts
Normal file
190
demo/2-declaritive-styles.ts
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
// Example on how to customise the look at feel using Styles
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
convertInchesToTwip,
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
LevelFormat,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
TextRun,
|
||||||
|
UnderlineType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Clippy",
|
||||||
|
title: "Sample Document",
|
||||||
|
description: "A brief example of using docx",
|
||||||
|
styles: {
|
||||||
|
default: {
|
||||||
|
heading1: {
|
||||||
|
run: {
|
||||||
|
size: 28,
|
||||||
|
bold: true,
|
||||||
|
italics: true,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
after: 120,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
heading2: {
|
||||||
|
run: {
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.DOUBLE,
|
||||||
|
color: "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
before: 240,
|
||||||
|
after: 120,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
listParagraph: {
|
||||||
|
run: {
|
||||||
|
color: "#FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "aside",
|
||||||
|
name: "Aside",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "999999",
|
||||||
|
italics: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
indent: {
|
||||||
|
left: convertInchesToTwip(0.5),
|
||||||
|
},
|
||||||
|
spacing: {
|
||||||
|
line: 276,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "wellSpaced",
|
||||||
|
name: "Well Spaced",
|
||||||
|
basedOn: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.LOWER_LETTER,
|
||||||
|
text: "%1)",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Test heading1, bold and italicized",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph("Some simple content"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Test heading2 with double red underline",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Option1",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Option5 -- override 2 to 5",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Option3",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Some monospaced content",
|
||||||
|
font: {
|
||||||
|
name: "Monospace",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "An aside, in light gray italics and indented",
|
||||||
|
style: "aside",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "This is normal, but well-spaced text",
|
||||||
|
style: "wellSpaced",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "This is a bold run,",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun(" switching to normal "),
|
||||||
|
new TextRun({
|
||||||
|
text: "and then underlined ",
|
||||||
|
underline: {},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "and then emphasis-mark ",
|
||||||
|
emphasisMark: {},
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "and back to normal.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
style: "Strong",
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Strong Style",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " - Very strong.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
103
demo/20-table-cell-borders.ts
Normal file
103
demo/20-table-cell-borders.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// Add custom borders to table cell
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_DOT_STROKED,
|
||||||
|
size: 3,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DOUBLE,
|
||||||
|
size: 3,
|
||||||
|
color: "blue",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_DOT_STROKED,
|
||||||
|
size: 3,
|
||||||
|
color: "green",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_DOT_STROKED,
|
||||||
|
size: 3,
|
||||||
|
color: "#ff8000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({ children: [table] });
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
40
demo/21-bookmarks.ts
Normal file
40
demo/21-bookmarks.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// 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 * as fs from "fs";
|
||||||
|
import { Bookmark, Document, HeadingLevel, HyperlinkRef, HyperlinkType, Packer, PageBreak, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const LOREM_IPSUM =
|
||||||
|
"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({
|
||||||
|
creator: "Clippy",
|
||||||
|
title: "Sample Document",
|
||||||
|
description: "A brief example of using docx with bookmarks and internal hyperlinks",
|
||||||
|
hyperlinks: {
|
||||||
|
myAnchorId: {
|
||||||
|
text: "Hyperlink",
|
||||||
|
type: HyperlinkType.INTERNAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
children: [new Bookmark("myAnchorId", "Lorem Ipsum")],
|
||||||
|
}),
|
||||||
|
new Paragraph("\n"),
|
||||||
|
new Paragraph(LOREM_IPSUM),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new HyperlinkRef("myAnchorId")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
44
demo/22-right-to-left-text.ts
Normal file
44
demo/22-right-to-left-text.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// This demo shows right to left for special languages
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
bidirectional: true,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "שלום עולם",
|
||||||
|
rightToLeft: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
bidirectional: true,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "שלום עולם",
|
||||||
|
bold: true,
|
||||||
|
rightToLeft: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
bidirectional: true,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "שלום עולם",
|
||||||
|
italics: true,
|
||||||
|
rightToLeft: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
32
demo/23-base64-images.ts
Normal file
32
demo/23-base64-images.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// This demo adds an image to the Media cache, and then insert to the document afterwards
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Media, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/dog.png"));
|
||||||
|
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"));
|
||||||
|
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"));
|
||||||
|
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
|
||||||
|
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 image6 = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World"), image5],
|
||||||
|
}),
|
||||||
|
new Paragraph(image),
|
||||||
|
new Paragraph(image2),
|
||||||
|
new Paragraph(image3),
|
||||||
|
new Paragraph(image4),
|
||||||
|
new Paragraph(image6),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
85
demo/24-images-to-table-cell.ts
Normal file
85
demo/24-images-to-table-cell.ts
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// Add image to table cell
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Media, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(image)],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
33
demo/26-paragraph-borders.ts
Normal file
33
demo/26-paragraph-borders.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Creates two paragraphs, one with a border and one without
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph("No border!"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "I have borders on my top and bottom sides!",
|
||||||
|
border: {
|
||||||
|
top: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
67
demo/27-declaritive-styles-3.ts
Normal file
67
demo/27-declaritive-styles-3.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Custom styles using JavaScript configuration
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "myWonkyStyle",
|
||||||
|
name: "My Wonky Style",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "990000",
|
||||||
|
italics: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
indent: {
|
||||||
|
left: convertInchesToTwip(0.5),
|
||||||
|
},
|
||||||
|
spacing: {
|
||||||
|
line: 276,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "Heading2",
|
||||||
|
name: "Heading 2",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
size: 26,
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.DOUBLE,
|
||||||
|
color: "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
before: 240,
|
||||||
|
after: 120,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello",
|
||||||
|
style: "myWonkyStyle",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "World",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
64
demo/28-table-of-contents.ts
Normal file
64
demo/28-table-of-contents.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Table of contents
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
|
||||||
|
|
||||||
|
const doc = new File({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "MySpectacularStyle",
|
||||||
|
name: "My Spectacular Style",
|
||||||
|
basedOn: "Heading1",
|
||||||
|
next: "Heading1",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
italics: true,
|
||||||
|
color: "990000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// WordprocessingML docs for TableOfContents can be found here:
|
||||||
|
// http://officeopenxml.com/WPtableOfContents.php
|
||||||
|
|
||||||
|
// Let's define the properties for generate a TOC for heading 1-5 and MySpectacularStyle,
|
||||||
|
// making the entries be hyperlinks for the paragraph
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new TableOfContents("Summary", {
|
||||||
|
hyperlink: true,
|
||||||
|
headingStyleRange: "1-5",
|
||||||
|
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Header #1",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
pageBreakBefore: true,
|
||||||
|
}),
|
||||||
|
new Paragraph("I'm a little text very nicely written.'"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Header #2",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
pageBreakBefore: true,
|
||||||
|
}),
|
||||||
|
new Paragraph("I'm a other text very nicely written.'"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Header #2.1",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
new Paragraph("I'm a another text very nicely written.'"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "My Spectacular Style #1",
|
||||||
|
style: "MySpectacularStyle",
|
||||||
|
pageBreakBefore: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
266
demo/29-numbered-lists.ts
Normal file
266
demo/29-numbered-lists.ts
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
// Numbered lists
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.UPPER_ROMAN,
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL_ZERO,
|
||||||
|
text: "[%1]",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "line with contextual spacing",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
contextualSpacing: true,
|
||||||
|
spacing: {
|
||||||
|
before: 200,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "line with contextual spacing",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
contextualSpacing: true,
|
||||||
|
spacing: {
|
||||||
|
before: 200,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "line without contextual spacing",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
contextualSpacing: false,
|
||||||
|
spacing: {
|
||||||
|
before: 200,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "line without contextual spacing",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
contextualSpacing: false,
|
||||||
|
spacing: {
|
||||||
|
before: 200,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 1 - Add sugar",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 2 - Add wheat",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 3 - Put in oven",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
142
demo/3-numbering-and-bullet-points.ts
Normal file
142
demo/3-numbering-and-bullet-points.ts
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
// Numbering and bullet points example
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertInchesToTwip, Document, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.UPPER_ROMAN,
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%2.",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 2,
|
||||||
|
format: LevelFormat.LOWER_LETTER,
|
||||||
|
text: "%3)",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 3,
|
||||||
|
format: LevelFormat.UPPER_LETTER,
|
||||||
|
text: "%4)",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 2880, hanging: 2420 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World 2",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Yeah boi",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hey you",
|
||||||
|
bullet: {
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "What's up fam",
|
||||||
|
bullet: {
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World 2",
|
||||||
|
bullet: {
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Yeah boi",
|
||||||
|
bullet: {
|
||||||
|
level: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "101 MSXFM",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "back to level 1",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "back to level 0",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
30
demo/30-template-document.ts
Normal file
30
demo/30-template-document.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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(undefined, {
|
||||||
|
template: templateDocument,
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
titlePage: templateDocument.titlePageIsDefined,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
76
demo/31-tables.ts
Normal file
76
demo/31-tables.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// Example of how you would create a table and add data to it
|
||||||
|
// 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 } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = 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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
408
demo/32-merge-and-shade-table-cells.ts
Normal file
408
demo/32-merge-and-shade-table-cells.ts
Normal file
@ -0,0 +1,408 @@
|
|||||||
|
// Example of how you would merge cells together (Rows and Columns) and apply shading
|
||||||
|
// Also includes an example on how to center tables
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
BorderStyle,
|
||||||
|
convertInchesToTwip,
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
ShadingType,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table2 = new Table({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
margins: {
|
||||||
|
top: convertInchesToTwip(0.69),
|
||||||
|
bottom: convertInchesToTwip(0.69),
|
||||||
|
left: convertInchesToTwip(0.69),
|
||||||
|
right: convertInchesToTwip(0.69),
|
||||||
|
},
|
||||||
|
columnSpan: 3,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.AUTO,
|
||||||
|
},
|
||||||
|
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table3 = new Table({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Foo")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("v")],
|
||||||
|
columnSpan: 3,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Bar1")],
|
||||||
|
shading: {
|
||||||
|
fill: "b79c2f",
|
||||||
|
val: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "auto",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Bar2")],
|
||||||
|
shading: {
|
||||||
|
fill: "42c5f4",
|
||||||
|
val: ShadingType.PERCENT_95,
|
||||||
|
color: "auto",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Bar3")],
|
||||||
|
shading: {
|
||||||
|
fill: "880aa8",
|
||||||
|
val: ShadingType.PERCENT_10,
|
||||||
|
color: "e2df0b",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Bar4")],
|
||||||
|
shading: {
|
||||||
|
fill: "FF0000",
|
||||||
|
val: ShadingType.CLEAR,
|
||||||
|
color: "auto",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: convertInchesToTwip(4.86),
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
margins: {
|
||||||
|
top: convertInchesToTwip(0.27),
|
||||||
|
bottom: convertInchesToTwip(0.27),
|
||||||
|
right: convertInchesToTwip(0.27),
|
||||||
|
left: convertInchesToTwip(0.27),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const table4 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.PERCENTAGE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const table5 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,1")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,2")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.PERCENTAGE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const borders = {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const table6 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders,
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
borders,
|
||||||
|
children: [new Paragraph("0,1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders,
|
||||||
|
children: [new Paragraph("1,1")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders,
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.PERCENTAGE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const table7 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,2")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,3")],
|
||||||
|
rowSpan: 3,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,0")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,2")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,3")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.PERCENTAGE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const table8 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({ children: [new Paragraph("1,1")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("1,2")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("1,3")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("1,4")], rowSpan: 4, borders }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({ children: [new Paragraph("2,1")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("2,2")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("2,3")], rowSpan: 3 }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({ children: [new Paragraph("3,1")] }),
|
||||||
|
new TableCell({ children: [new Paragraph("3,2")], rowSpan: 2 }),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [new TableCell({ children: [new Paragraph("4,1")] })],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.PERCENTAGE,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
table,
|
||||||
|
new Paragraph({
|
||||||
|
text: "Another table",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
table2,
|
||||||
|
new Paragraph({
|
||||||
|
text: "Another table",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
table3,
|
||||||
|
new Paragraph("Merging columns 1"),
|
||||||
|
table4,
|
||||||
|
new Paragraph("Merging columns 2"),
|
||||||
|
table5,
|
||||||
|
new Paragraph("Merging columns 3"),
|
||||||
|
table6,
|
||||||
|
new Paragraph("Merging columns 4"),
|
||||||
|
table7,
|
||||||
|
new Paragraph("Merging columns 5"),
|
||||||
|
table8,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
47
demo/33-sequential-captions.ts
Normal file
47
demo/33-sequential-captions.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Sequential Captions
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World 1->"),
|
||||||
|
new SequentialIdentifier("Caption"),
|
||||||
|
new TextRun(" text after sequencial caption 2->"),
|
||||||
|
new SequentialIdentifier("Caption"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World 1->"),
|
||||||
|
new SequentialIdentifier("Label"),
|
||||||
|
new TextRun(" text after sequencial caption 2->"),
|
||||||
|
new SequentialIdentifier("Label"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World 1->"),
|
||||||
|
new SequentialIdentifier("Another"),
|
||||||
|
new TextRun(" text after sequencial caption 3->"),
|
||||||
|
new SequentialIdentifier("Label"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World 2->"),
|
||||||
|
new SequentialIdentifier("Another"),
|
||||||
|
new TextRun(" text after sequencial caption 4->"),
|
||||||
|
new SequentialIdentifier("Label"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
62
demo/34-floating-tables.ts
Normal file
62
demo/34-floating-tables.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Example of how you would create a table with float positions
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
OverlapType,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
RelativeHorizontalPosition,
|
||||||
|
RelativeVerticalPosition,
|
||||||
|
Table,
|
||||||
|
TableAnchorType,
|
||||||
|
TableCell,
|
||||||
|
TableLayoutType,
|
||||||
|
TableRow,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
float: {
|
||||||
|
horizontalAnchor: TableAnchorType.MARGIN,
|
||||||
|
verticalAnchor: TableAnchorType.MARGIN,
|
||||||
|
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
|
||||||
|
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
|
||||||
|
overlap: OverlapType.NEVER,
|
||||||
|
},
|
||||||
|
width: {
|
||||||
|
size: 4535,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
layout: TableLayoutType.FIXED,
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
36
demo/35-hyperlinks.ts
Normal file
36
demo/35-hyperlinks.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Example on how to add hyperlinks to websites
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph, Media } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
hyperlinks: {
|
||||||
|
myCoolLink: {
|
||||||
|
link: "http://www.example.com",
|
||||||
|
text: "Hyperlink",
|
||||||
|
type: HyperlinkType.EXTERNAL,
|
||||||
|
},
|
||||||
|
myOtherLink: {
|
||||||
|
link: "http://www.google.com",
|
||||||
|
text: "Google Link",
|
||||||
|
type: HyperlinkType.EXTERNAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new HyperlinkRef("myCoolLink")],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [image1, new HyperlinkRef("myOtherLink")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
72
demo/36-image-to-table-cell.ts
Normal file
72
demo/36-image-to-table-cell.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// Add image to table cell in a header and body
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Header, Media, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(image)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adding same table in the body and in the header
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [table],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
22
demo/37-images-to-header-and-footer.ts
Normal file
22
demo/37-images-to-header-and-footer.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Add images to header and footer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Header, Media, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [new Paragraph(image), new Paragraph(image1), new Paragraph(image2)],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
45
demo/38-text-wrapping.ts
Normal file
45
demo/38-text-wrapping.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Example of how to "wrap" text around an image
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
// import { Document, Packer, Paragraph } from "../build";
|
||||||
|
import { Document, Media, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
wrap: {
|
||||||
|
type: TextWrappingType.SQUARE,
|
||||||
|
side: TextWrappingSide.BOTH_SIDES,
|
||||||
|
},
|
||||||
|
margins: {
|
||||||
|
top: 201440,
|
||||||
|
bottom: 201440,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Proin ac purus faucibus, porttitor magna ut, cursus nisl. Vivamus ante purus, porta accumsan nibh eget, eleifend dignissim odio. Integer sed dictum est, aliquam lacinia justo. Donec ultrices auctor venenatis. Etiam interdum et elit nec elementum. Pellentesque nec viverra mauris. Etiam suscipit leo nec velit fringilla mattis. Pellentesque justo lacus, sodales eu condimentum in, dapibus finibus lacus. Morbi vitae nibh sit amet sem molestie feugiat. In non porttitor enim.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.",
|
||||||
|
),
|
||||||
|
new Paragraph(image),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
69
demo/39-page-numbers.ts
Normal file
69
demo/39-page-numbers.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Example how to display page numbers
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Foo Bar corp. "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page Number ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [" to ", PageNumber.TOTAL_PAGES],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
children: [
|
||||||
|
new TextRun("Foo Bar corp. "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page Number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [" to ", PageNumber.TOTAL_PAGES],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberStart: 1,
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 1"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 2"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 3"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 4"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 5"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
39
demo/4-basic-table.ts
Normal file
39
demo/4-basic-table.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Example of how you would create a table and add data to it
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
29
demo/40-line-numbers.ts
Normal file
29
demo/40-line-numbers.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Example demonstrating line numbers.
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
lineNumberCountBy: 1,
|
||||||
|
lineNumberRestart: LineNumberRestartFormat.CONTINUOUS,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph(
|
||||||
|
"Himenaeos duis luctus nullam fermentum lobortis potenti vivamus non dis, sed facilisis ultricies scelerisque aenean risus hac senectus. Adipiscing id venenatis justo ante gravida placerat, ac curabitur dis pellentesque proin bibendum risus, aliquam porta taciti vulputate primis. Tortor ipsum fermentum quam vel convallis primis nisl praesent tincidunt, lobortis quisque felis vitae condimentum class ut sem nam, aenean potenti pretium ac amet lacinia himenaeos mi. Aliquam nisl turpis hendrerit est morbi malesuada, augue interdum mus inceptos curabitur tristique, parturient feugiat sodales nulla facilisi. Aliquam non pulvinar purus nulla ex integer, velit faucibus vitae at bibendum quam, risus elit aenean adipiscing posuere.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
261
demo/41-merge-table-cells-2.ts
Normal file
261
demo/41-merge-table-cells-2.ts
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
// Multiple cells merging in the same table - Rows and Columns
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,1")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,4")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,0")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,2")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,4")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,1")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,4")],
|
||||||
|
columnSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,0")],
|
||||||
|
columnSpan: 5,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table2 = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,1")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("0,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("1,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("2,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("3,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,0")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,2")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,4")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("4,5")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table, new Paragraph(""), table2],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
84
demo/43-images-to-table-cell-2.ts
Normal file
84
demo/43-images-to-table-cell-2.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Add image to table cell
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
40
demo/44-multiple-columns.ts
Normal file
40
demo/44-multiple-columns.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Sections with multiple columns
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
column: {
|
||||||
|
space: 708,
|
||||||
|
count: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph("This text will be split into 2 columns on a page."),
|
||||||
|
new Paragraph(
|
||||||
|
"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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
column: {
|
||||||
|
space: 708,
|
||||||
|
count: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph("This text will be split into 3 columns on a page."),
|
||||||
|
new Paragraph(
|
||||||
|
"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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
35
demo/45-highlighting-text.ts
Normal file
35
demo/45-highlighting-text.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Highlighting text
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Hello World",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
font: {
|
||||||
|
name: "Garamond",
|
||||||
|
},
|
||||||
|
highlight: "yellow",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
51
demo/46-shading-text.ts
Normal file
51
demo/46-shading-text.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Shading text
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Hello World",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
font: {
|
||||||
|
name: "Garamond",
|
||||||
|
},
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.DIAGONAL_CROSS,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Hello World for entire paragraph",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
67
demo/47-number-of-total-pages-section.ts
Normal file
67
demo/47-number-of-total-pages-section.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Multiple sections with total number of pages in each section
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const header = new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Header on another page"),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
children: [" to ", PageNumber.TOTAL_PAGES_IN_SECTION],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const footer = new Footer({
|
||||||
|
children: [new Paragraph("Foo Bar corp. ")],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: header,
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: footer,
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberStart: 1,
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Section 1"), new PageBreak(), new TextRun("Section 1"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: header,
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: footer,
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
pageNumberStart: 1,
|
||||||
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Section 2"), new PageBreak(), new TextRun("Section 2"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
31
demo/48-vertical-align.ts
Normal file
31
demo/48-vertical-align.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Example of making content of section vertically aligned
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {
|
||||||
|
verticalAlign: SectionVerticalAlignValue.CENTER,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
167
demo/49-table-borders.ts
Normal file
167
demo/49-table-borders.ts
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
// Add custom borders and no-borders to the table itself
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
BorderStyle,
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableBorders,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
TextDirection,
|
||||||
|
VerticalAlign,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Using the no-border convenience object. It is the same as writing this manually:
|
||||||
|
// const borders = {
|
||||||
|
// top: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// bottom: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// left: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// right: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// insideHorizontal: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// insideVertical: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
const noBorderTable = new Table({
|
||||||
|
borders: TableBorders.NONE,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({}), new Paragraph({})],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({}), new Paragraph({})],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||||
|
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text:
|
||||||
|
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "This text should be in the middle of the cell",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Text above should be vertical from bottom to top",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Text above should be vertical from top to bottom",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({ children: [table, new Paragraph("Hello"), noBorderTable] });
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
64
demo/5-images.ts
Normal file
64
demo/5-images.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Example of how to add images to the document - You can use Buffers, UInt8Arrays or Base64 strings
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
// import { Document, Packer, Paragraph } from "../build";
|
||||||
|
import {
|
||||||
|
Document,
|
||||||
|
HorizontalPositionAlign,
|
||||||
|
HorizontalPositionRelativeFrom,
|
||||||
|
Media,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
VerticalPositionAlign,
|
||||||
|
VerticalPositionRelativeFrom,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/dog.png").toString("base64"));
|
||||||
|
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"));
|
||||||
|
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"));
|
||||||
|
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
zIndex: 10,
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
zIndex: 5,
|
||||||
|
horizontalPosition: {
|
||||||
|
relative: HorizontalPositionRelativeFrom.PAGE,
|
||||||
|
align: HorizontalPositionAlign.RIGHT,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
relative: VerticalPositionRelativeFrom.PAGE,
|
||||||
|
align: VerticalPositionAlign.BOTTOM,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph("Hello World"),
|
||||||
|
new Paragraph(image1),
|
||||||
|
new Paragraph(image2),
|
||||||
|
new Paragraph(image3),
|
||||||
|
new Paragraph(image4),
|
||||||
|
new Paragraph(image5),
|
||||||
|
new Paragraph(image6),
|
||||||
|
new Paragraph(image7),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
61
demo/50-readme-demo.ts
Normal file
61
demo/50-readme-demo.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// 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, HeadingLevel, Media, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(image1)],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "World",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph(image1)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
table,
|
||||||
|
new Paragraph(image2),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
57
demo/51-character-styles.ts
Normal file
57
demo/51-character-styles.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Custom character styles using JavaScript configuration
|
||||||
|
// 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({
|
||||||
|
styles: {
|
||||||
|
characterStyles: [
|
||||||
|
{
|
||||||
|
id: "myRedStyle",
|
||||||
|
name: "My Wonky Style",
|
||||||
|
basedOn: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "990000",
|
||||||
|
italics: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "strong",
|
||||||
|
name: "Strong",
|
||||||
|
basedOn: "Normal",
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo bar",
|
||||||
|
style: "myRedStyle",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "First Word",
|
||||||
|
style: "strong",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
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.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
37
demo/52-japanese.ts
Normal file
37
demo/52-japanese.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Japanese text - Need to use a Japanese font
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "Normal",
|
||||||
|
name: "Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "MS Gothic",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "KFCを食べるのが好き",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "こんにちは",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
55
demo/53-chinese.ts
Normal file
55
demo/53-chinese.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Chinese text - Chinese text need to use a Chinese font. And ascii text need to use a ascii font.
|
||||||
|
// Different from the `52-japanese.ts`.
|
||||||
|
// `52-japanese.ts` will set all characters to use Japanese font.
|
||||||
|
// `53-chinese.ts` will set Chinese characters to use Chinese font, and set ascii characters to use ascii font.
|
||||||
|
|
||||||
|
// Note that if the OS have not install `KaiTi` font, this demo doesn't work.
|
||||||
|
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "Normal",
|
||||||
|
name: "Normal",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: {
|
||||||
|
ascii: "Times",
|
||||||
|
eastAsia: "KaiTi",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "中文和英文 Chinese and English",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "中文和英文 Chinese and English",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "中文和英文 Chinese and English",
|
||||||
|
font: { eastAsia: "SimSun" }, // set eastAsia to "SimSun".
|
||||||
|
// The ascii characters will use the default font ("Times") specified in paragraphStyles
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
146
demo/54-track-revisions.ts
Normal file
146
demo/54-track-revisions.ts
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
// Track Revisions aka. "Track Changes"
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
DeletedTextRun,
|
||||||
|
Document,
|
||||||
|
Footer,
|
||||||
|
FootnoteReferenceRun,
|
||||||
|
InsertedTextRun,
|
||||||
|
Packer,
|
||||||
|
PageNumber,
|
||||||
|
Paragraph,
|
||||||
|
ShadingType,
|
||||||
|
TextRun,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
/*
|
||||||
|
For reference, see
|
||||||
|
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.insertedrun
|
||||||
|
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.deletedrun
|
||||||
|
|
||||||
|
The method `addTrackRevisions()` adds an element `<w:trackRevisions />` to the `settings.xml` file. This specifies that the application shall track *new* revisions made to the existing document.
|
||||||
|
See also https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.trackrevisions
|
||||||
|
|
||||||
|
Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
footnotes: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a footnote"),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: " with some extra text which was deleted",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: " and new content",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
features: {
|
||||||
|
trackRevisions: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo "),
|
||||||
|
new TextRun({
|
||||||
|
text: "on how to ",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "mark a text as an insertion ",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "or a deletion.",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
paragraph,
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a demo "),
|
||||||
|
new DeletedTextRun({
|
||||||
|
break: 1,
|
||||||
|
text: "in order",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
font: {
|
||||||
|
name: "Garamond",
|
||||||
|
},
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
id: 2,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "to show how to ",
|
||||||
|
bold: false,
|
||||||
|
id: 3,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
bold: true,
|
||||||
|
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
children: [
|
||||||
|
new TextRun("Awesome LLC"),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page Number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
children: [" to ", PageNumber.TOTAL_PAGES],
|
||||||
|
id: 4,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
children: [" from ", PageNumber.TOTAL_PAGES],
|
||||||
|
bold: true,
|
||||||
|
id: 5,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
294
demo/55-math.ts
Normal file
294
demo/55-math.ts
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
// 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,
|
||||||
|
Math,
|
||||||
|
MathAngledBrackets,
|
||||||
|
MathCurlyBrackets,
|
||||||
|
MathFraction,
|
||||||
|
MathFunction,
|
||||||
|
MathPreSubSuperScript,
|
||||||
|
MathRadical,
|
||||||
|
MathRoundBrackets,
|
||||||
|
MathRun,
|
||||||
|
MathSquareBrackets,
|
||||||
|
MathSubScript,
|
||||||
|
MathSubSuperScript,
|
||||||
|
MathSum,
|
||||||
|
MathSuperScript,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
TextRun,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2+2"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("hi")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRun("1"),
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSum({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
}),
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
subScript: [new MathRun("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
subScript: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("y")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathPreSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
degree: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("x")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFunction({
|
||||||
|
name: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
children: [new MathRun("100")],
|
||||||
|
}),
|
||||||
|
new MathRun("×"),
|
||||||
|
new MathFunction({
|
||||||
|
name: [new MathRun("sin")],
|
||||||
|
children: [new MathRun("360")],
|
||||||
|
}),
|
||||||
|
new MathRun("= x"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRoundBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathSquareBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathCurlyBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathAngledBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2a")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
33
demo/56-background-color.ts
Normal file
33
demo/56-background-color.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Change background colour of whole 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({
|
||||||
|
background: {
|
||||||
|
color: "C45911",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
88
demo/57-add-parent-numbered-lists.ts
Normal file
88
demo/57-add-parent-numbered-lists.ts
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Numbered lists - Add parent number in sub number
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: 260 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1.%2",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 1.25 * convertInchesToTwip(0.5), hanging: 1.25 * 260 },
|
||||||
|
},
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
size: 18,
|
||||||
|
font: "Times New Roman",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "How to make cake",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 1 - Add sugar",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 2 - Add wheat",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 2a - Stir the wheat in a circle",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 3 - Put in oven",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "How to make cake",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
40
demo/6-page-borders.ts
Normal file
40
demo/6-page-borders.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Example of how to change page borders
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
margins: {
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph("Foo bar"),
|
||||||
|
new Paragraph("Github is the best"),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
17
demo/7-landscape.ts
Normal file
17
demo/7-landscape.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Example of how to set the document to landscape
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.LANDSCAPE,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
24
demo/8-header-footer.ts
Normal file
24
demo/8-header-footer.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Add text to header and footer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [new Paragraph("Header text")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [new Paragraph("Footer text")],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
35
demo/9-images-in-header-and-footer.ts
Normal file
35
demo/9-images-in-header-and-footer.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Add images to header and footer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Media, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [image1],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [image2],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
2
demo/assets/custom-styles.xml
Normal file
2
demo/assets/custom-styles.xml
Normal file
File diff suppressed because one or more lines are too long
45
demo/browser-demo.html
Normal file
45
demo/browser-demo.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../build/index.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>DOCX browser Word document generation</h1>
|
||||||
|
|
||||||
|
<button type="button" onclick="generate()">Click to generate document</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function generate() {
|
||||||
|
const doc = new docx.Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new docx.Paragraph({
|
||||||
|
children: [
|
||||||
|
new docx.TextRun("Hello World"),
|
||||||
|
new docx.TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new docx.TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
docx.Packer.toBlob(doc).then((blob) => {
|
||||||
|
console.log(blob);
|
||||||
|
saveAs(blob, "example.docx");
|
||||||
|
console.log("Document created successfully");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,16 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
var paragraph = new docx.Paragraph("Hello World");
|
|
||||||
var institutionText = new docx.TextRun("University College London").bold();
|
|
||||||
var dateText = new docx.TextRun("5th Dec 2015").tab().bold();
|
|
||||||
paragraph.addRun(institutionText);
|
|
||||||
paragraph.addRun(dateText);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,74 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
const doc = new docx.Document({
|
|
||||||
creator: 'Clippy',
|
|
||||||
title: 'Sample Document',
|
|
||||||
description: 'A brief example of using docx',
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle('Heading1', 'Heading 1')
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.quickFormat()
|
|
||||||
.size(28)
|
|
||||||
.bold()
|
|
||||||
.italics()
|
|
||||||
.spacing({after: 120});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle('Heading2', 'Heading 2')
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.quickFormat()
|
|
||||||
.size(26)
|
|
||||||
.bold()
|
|
||||||
.underline('double', 'FF0000')
|
|
||||||
.spacing({before: 240, after: 120});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle('aside', 'Aside')
|
|
||||||
.basedOn('Normal')
|
|
||||||
.next('Normal')
|
|
||||||
.color('999999')
|
|
||||||
.italics()
|
|
||||||
.indent(720)
|
|
||||||
.spacing({line: 276});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle('wellSpaced', 'Well Spaced')
|
|
||||||
.basedOn('Normal')
|
|
||||||
.spacing({line: 276, before: 20 * 72 * .1, after: 20 * 72 * .05});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle('ListParagraph', 'List Paragraph')
|
|
||||||
.quickFormat()
|
|
||||||
.basedOn('Normal');
|
|
||||||
|
|
||||||
|
|
||||||
const numberedAbstract = doc.Numbering.createAbstractNumbering();
|
|
||||||
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "left");
|
|
||||||
|
|
||||||
doc.createParagraph('Test heading1, bold and italicized').heading1();
|
|
||||||
doc.createParagraph('Some simple content');
|
|
||||||
doc.createParagraph('Test heading2 with double red underline').heading2();
|
|
||||||
|
|
||||||
const letterNumbering = doc.Numbering.createConcreteNumbering(numberedAbstract);
|
|
||||||
const letterNumbering5 = doc.Numbering.createConcreteNumbering(numberedAbstract);
|
|
||||||
letterNumbering5.overrideLevel(0, 5);
|
|
||||||
|
|
||||||
doc.createParagraph('Option1').setNumbering(letterNumbering, 0);
|
|
||||||
doc.createParagraph('Option5 -- override 2 to 5').setNumbering(letterNumbering5, 0);
|
|
||||||
doc.createParagraph('Option3').setNumbering(letterNumbering, 0);
|
|
||||||
|
|
||||||
doc.createParagraph()
|
|
||||||
.createTextRun('Some monospaced content')
|
|
||||||
.font('Monospace');
|
|
||||||
|
|
||||||
doc.createParagraph('An aside, in light gray italics and indented').style('aside');
|
|
||||||
doc.createParagraph('This is normal, but well-spaced text').style('wellSpaced');
|
|
||||||
const para = doc.createParagraph();
|
|
||||||
para.createTextRun('This is a bold run,').bold();
|
|
||||||
para.createTextRun(' switching to normal ');
|
|
||||||
para.createTextRun('and then underlined ').underline();
|
|
||||||
para.createTextRun('and back to normal.');
|
|
||||||
|
|
||||||
const exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,35 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
const numbering = new docx.Numbering();
|
|
||||||
|
|
||||||
const abstractNum = numbering.createAbstractNumbering();
|
|
||||||
abstractNum.createLevel(0, "upperRoman", "%1", "start")
|
|
||||||
.addParagraphProperty(new docx.Indent(720, 260));
|
|
||||||
abstractNum.createLevel(1, "decimal", "%2.", "start")
|
|
||||||
.addParagraphProperty(new docx.Indent(1440, 980));
|
|
||||||
abstractNum.createLevel(2, "lowerLetter", "%3)", "start")
|
|
||||||
.addParagraphProperty(new docx.Indent(2160, 1700));
|
|
||||||
|
|
||||||
const concrete = numbering.createConcreteNumbering(abstractNum);
|
|
||||||
|
|
||||||
var topLevelP = new docx.Paragraph("Hey you");
|
|
||||||
var subP = new docx.Paragraph("What's up fam");
|
|
||||||
var secondSubP = new docx.Paragraph("Hello World 2");
|
|
||||||
var subSubP = new docx.Paragraph("Yeah boi");
|
|
||||||
|
|
||||||
topLevelP.setNumbering(concrete, 0);
|
|
||||||
subP.setNumbering(concrete, 1);
|
|
||||||
secondSubP.setNumbering(concrete, 1);
|
|
||||||
subSubP.setNumbering(concrete, 2);
|
|
||||||
|
|
||||||
doc.addParagraph(topLevelP);
|
|
||||||
doc.addParagraph(subP);
|
|
||||||
doc.addParagraph(secondSubP);
|
|
||||||
doc.addParagraph(subSubP);
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,12 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
const table = doc.createTable(4, 4);
|
|
||||||
table.getCell(2, 2).addContent(new docx.Paragraph('Hello'));
|
|
||||||
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,17 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
var paragraph = new docx.Paragraph("Hello World");
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const image = doc.createImage("./demo/images/image1.jpeg");
|
|
||||||
const image2 = doc.createImage("./demo/images/dog.png");
|
|
||||||
const image3 = doc.createImage("./demo/images/cat.jpg");
|
|
||||||
const image4 = doc.createImage("./demo/images/parrots.bmp");
|
|
||||||
const image5 = doc.createImage("./demo/images/pizza.gif");
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,25 +0,0 @@
|
|||||||
const docx = require("../build");
|
|
||||||
|
|
||||||
var doc = new docx.Document(undefined, {
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
var paragraph = new docx.Paragraph("Hello World");
|
|
||||||
var institutionText = new docx.TextRun("University College London").bold();
|
|
||||||
var dateText = new docx.TextRun("5th Dec 2015").tab().bold();
|
|
||||||
paragraph.addRun(institutionText);
|
|
||||||
paragraph.addRun(dateText);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World").heading1();
|
|
||||||
doc.createParagraph("University College London");
|
|
||||||
doc.createParagraph("5th Dec 2015");
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack("My Document");
|
|
||||||
|
|
||||||
console.log("Document created successfully at project root!");
|
|
@ -1,14 +0,0 @@
|
|||||||
const docx = require("../build");
|
|
||||||
|
|
||||||
var doc = new docx.Document(undefined, {
|
|
||||||
orientation: "landscape",
|
|
||||||
});
|
|
||||||
|
|
||||||
var paragraph = new docx.Paragraph("Hello World");
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack("My Document");
|
|
||||||
|
|
||||||
console.log("Document created successfully at project root!");
|
|
@ -1,13 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World");
|
|
||||||
|
|
||||||
doc.Header.createParagraph("Header text");
|
|
||||||
doc.Footer.createParagraph("Footer text");
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
@ -1,13 +0,0 @@
|
|||||||
const docx = require('../build');
|
|
||||||
|
|
||||||
var doc = new docx.Document();
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World");
|
|
||||||
|
|
||||||
doc.Header.createImage("./demo/images/pizza.gif");
|
|
||||||
doc.Footer.createImage("./demo/images/pizza.gif");
|
|
||||||
|
|
||||||
var exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack('My Document');
|
|
||||||
|
|
||||||
console.log('Document created successfully at project root!');
|
|
BIN
demo/dotx/template.dotx
Normal file
BIN
demo/dotx/template.dotx
Normal file
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
var prompt = require('prompt');
|
|
||||||
var shelljs = require('shelljs');
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
console.log('What demo do you wish to run? (Enter a number)');
|
|
||||||
|
|
||||||
var schema = {
|
|
||||||
properties: {
|
|
||||||
number: {
|
|
||||||
pattern: /^[0-9]+$/,
|
|
||||||
message: 'Please enter a number.',
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
prompt.start();
|
|
||||||
|
|
||||||
prompt.get(schema, function (err, result) {
|
|
||||||
var demoNumber = result.number;
|
|
||||||
var filePath = `./demo/demo${demoNumber}.js`;
|
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
|
||||||
console.error(`demo${demoNumber} does not exist: ${filePath}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log(`Running demo ${demoNumber}`);
|
|
||||||
shelljs.exec(`node ${filePath}`);
|
|
||||||
});
|
|
37
demo/index.ts
Normal file
37
demo/index.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// tslint:disable:no-console
|
||||||
|
import * as fs from "fs";
|
||||||
|
import * as prompt from "prompt";
|
||||||
|
import * as shelljs from "shelljs";
|
||||||
|
|
||||||
|
console.log("What demo do you wish to run? (Enter a number)");
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
properties: {
|
||||||
|
number: {
|
||||||
|
pattern: /^[0-9]+$/,
|
||||||
|
message: "Please enter a number.",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
prompt.start();
|
||||||
|
|
||||||
|
prompt.get(schema, (_, result) => {
|
||||||
|
const demoNumber = result.number;
|
||||||
|
const files = fs.readdirSync("./demo").filter((fn) => fn.startsWith(demoNumber));
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
console.error(`demo number ${demoNumber} does not exist`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filePath = `./demo/${files[0]}`;
|
||||||
|
|
||||||
|
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
||||||
|
if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) {
|
||||||
|
console.log("Document created successfully");
|
||||||
|
} else {
|
||||||
|
console.error("Something went wrong with the demo");
|
||||||
|
}
|
||||||
|
});
|
@ -1,68 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e # Exit with nonzero exit code if anything fails
|
|
||||||
|
|
||||||
SOURCE_BRANCH="master"
|
|
||||||
TARGET_BRANCH="gh-pages"
|
|
||||||
|
|
||||||
function doCompile {
|
|
||||||
npm run typedoc
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
|
|
||||||
echo "Skipping deploy; just doing a build."
|
|
||||||
doCompile
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Save some useful information
|
|
||||||
REPO=`git config remote.origin.url`
|
|
||||||
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
|
|
||||||
SHA=`git rev-parse --verify HEAD`
|
|
||||||
|
|
||||||
# Clone the existing gh-pages for this repo into docs/
|
|
||||||
# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
|
|
||||||
git clone $REPO docs
|
|
||||||
cd docs
|
|
||||||
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# Clean out existing contents
|
|
||||||
# echo "Cleaning out existing contents."
|
|
||||||
# rm -rf docs/*
|
|
||||||
|
|
||||||
# Run our compile script
|
|
||||||
doCompile
|
|
||||||
|
|
||||||
# Now let's go have some fun with the cloned repo
|
|
||||||
cd docs
|
|
||||||
git config user.name "Travis CI"
|
|
||||||
git config user.email "dolan_miu@hotmail.com"
|
|
||||||
ls
|
|
||||||
|
|
||||||
# add .nojekyll file
|
|
||||||
touch .nojekyll
|
|
||||||
|
|
||||||
# If there are no changes to the compiled out (e.g. this is a README update) then just bail.
|
|
||||||
if [ -z `git diff --exit-code` ]; then
|
|
||||||
echo "No changes to the output on this push; exiting."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Commit the "changes", i.e. the new version.
|
|
||||||
# The delta will show diffs between new and old versions.
|
|
||||||
git add .
|
|
||||||
git commit -m "Deploy to GitHub Pages: ${SHA}"
|
|
||||||
|
|
||||||
# Get the deploy key by using Travis's stored variables to decrypt deploy-key.enc
|
|
||||||
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
|
|
||||||
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
|
|
||||||
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
|
|
||||||
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
|
|
||||||
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in deploy-key.enc -out deploy-key -d
|
|
||||||
chmod 600 deploy-key
|
|
||||||
eval `ssh-agent -s`
|
|
||||||
ssh-add deploy-key
|
|
||||||
|
|
||||||
# Now that we're all set up, we can push.
|
|
||||||
git push $SSH_REPO $TARGET_BRANCH
|
|
BIN
deploy-key.enc
BIN
deploy-key.enc
Binary file not shown.
65
docs/README.md
Normal file
65
docs/README.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Welcome
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save docx
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can `require` or `import` as usual:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const docx = require("docx");
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import * as docx from "docx";
|
||||||
|
// or
|
||||||
|
import { ... } from "docx";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||||
|
|
||||||
|
// Create document
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
// 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
|
||||||
|
doc.addSection({
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Used to export the file into a .docx file
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Done! A file called 'My Document.docx' will be in your file system.
|
||||||
|
```
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="clippy the assistant" src="./clippy.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Made with 💖
|
10
docs/_coverpage.md
Normal file
10
docs/_coverpage.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<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:
|
||||||
|
|
||||||
|
- Simple, declarative API
|
||||||
|
- 50+ usage examples
|
||||||
|
- Battle tested, mature, 95%+ coverage
|
||||||
|
|
||||||
|
[GitHub](https://github.com/dolanmiu/docx)
|
||||||
|
[Get Started](#Welcome)
|
35
docs/_sidebar.md
Normal file
35
docs/_sidebar.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
* [Getting Started](/)
|
||||||
|
|
||||||
|
* [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
|
|
||||||
|
* API
|
||||||
|
|
||||||
|
* [Documentation](https://docx.js.org/api/)
|
||||||
|
|
||||||
|
* Usage
|
||||||
|
|
||||||
|
* [Document](usage/document.md)
|
||||||
|
* [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)
|
||||||
|
* [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)
|
||||||
|
* Styling
|
||||||
|
* [Styling with JS](usage/styling-with-js.md)
|
||||||
|
* [Styling with XML](usage/styling-with-xml.md)
|
||||||
|
* Exporting
|
||||||
|
|
||||||
|
* [Packers](usage/packers.md)
|
||||||
|
* Utility
|
||||||
|
|
||||||
|
* [Convenience functions](usage/convenience-functions.md)
|
||||||
|
|
||||||
|
* [Contribution Guidelines](contribution-guidelines.md)
|
BIN
docs/clippy.png
Normal file
BIN
docs/clippy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
docs/clippy.psd
Normal file
BIN
docs/clippy.psd
Normal file
Binary file not shown.
195
docs/contribution-guidelines.md
Normal file
195
docs/contribution-guidelines.md
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
# Contribution Guidelines
|
||||||
|
|
||||||
|
- Include documentation reference(s) at the top of each file:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// http://officeopenxml.com/WPdocument.php
|
||||||
|
```
|
||||||
|
|
||||||
|
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
||||||
|
|
||||||
|
- Follow the `TSLint` rules
|
||||||
|
|
||||||
|
## Always think about the user
|
||||||
|
|
||||||
|
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
||||||
|
|
||||||
|
1. Is it easy to use?
|
||||||
|
2. Has it been documented well?
|
||||||
|
3. Is it intuitive?
|
||||||
|
4. Is it declarative?
|
||||||
|
5. Is it fun to use?
|
||||||
|
|
||||||
|
## Good Commit Names
|
||||||
|
|
||||||
|
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```
|
||||||
|
c // What?
|
||||||
|
rtl // Adding acryonyms without explaining anything else is not helpful
|
||||||
|
works! // Glad its working, but the message is not helpful
|
||||||
|
demo updated // Getting better, but capitalize the first letter
|
||||||
|
Unesesary coment removed // Make sure to use correct spelling
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do**
|
||||||
|
|
||||||
|
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
public float(tableFloatOptions: ITableFloatOptions): Table
|
||||||
|
```
|
||||||
|
|
||||||
|
## Delcariative 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
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = doc.createParagraph();
|
||||||
|
const text = paragraph.createText();
|
||||||
|
text.contents = "Hello World";
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getters and Setters
|
||||||
|
|
||||||
|
Getters and Setters are done with a capital letter like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
public get Level() {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the convention of this project. There is no performance advantage by doing this. It means we don't need to prefix all private variables with `_`:
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
private get _level: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
private get level: string;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Interfaces over type alias
|
||||||
|
|
||||||
|
Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it.
|
||||||
|
|
||||||
|
> "In general, use what you want ( type alias / interface ) just be consistent"
|
||||||
|
> "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
|
||||||
|
>
|
||||||
|
> - https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
|
||||||
|
|
||||||
|
`Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
type RelationshipFileInfo = { id: number; target: string };
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
interface IRelationshipFileInfo {
|
||||||
|
id: number;
|
||||||
|
target: string;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## String enums vs type
|
||||||
|
|
||||||
|
To take full advantage of TypeScript's typing system, its best to use `string enums`:
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
type WeaponType = "bow" | "sword" | "wand";
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
enum WeaponType = {
|
||||||
|
BOW = "bow",
|
||||||
|
SWORD = "sword",
|
||||||
|
WAND = "wand",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Spell correctly, in full and in American English
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
readdy; // misspelling
|
||||||
|
perm; // abbreviation
|
||||||
|
conf; // abbreviation
|
||||||
|
cnty; // abbreviation
|
||||||
|
relationFile; // abbreviation
|
||||||
|
colour; // U.K. English
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
ready;
|
||||||
|
permission;
|
||||||
|
config;
|
||||||
|
country;
|
||||||
|
relationshipFile;
|
||||||
|
color;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Keep files small (within reason)
|
||||||
|
|
||||||
|
To minimize merge conflicts, reduce complexity, and improve readability, keep the files small.
|
||||||
|
|
||||||
|
## Name files and folders with `/foo-bar/kebab-case.ts`
|
||||||
|
|
||||||
|
To be consistent and in-line with the project, name files `like-this.ts`.
|
||||||
|
|
||||||
|
https://stackoverflow.com/questions/7273316/what-is-the-javascript-filename-naming-convention
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Please write a test of every file you make and suffix it with `.spec.ts`.
|
||||||
|
|
||||||
|
Here is a template of a test:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { assert } from "chai";
|
||||||
|
|
||||||
|
describe("ClassName", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#methodName()", () => {
|
||||||
|
it("should ", () => {
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Try not to use the `tests/utility.ts` file as this is being deprecated.
|
BIN
docs/images/math-example.png
Normal file
BIN
docs/images/math-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
36
docs/index.html
Normal file
36
docs/index.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>docx - Generate .docx documents with JavaScript</title>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||||
|
<meta name="description" content="Generate .docx documents with JavaScript" />
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
|
||||||
|
title="docsify-darklight-theme"
|
||||||
|
type="text/css"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script>
|
||||||
|
window.$docsify = {
|
||||||
|
name: "docx",
|
||||||
|
repo: "https://github.com/dolanmiu/docx",
|
||||||
|
loadSidebar: true,
|
||||||
|
subMaxLevel: 2,
|
||||||
|
search: "auto",
|
||||||
|
coverpage: true,
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||||
|
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></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/prismjs/components/prism-typescript.min.js"></script>
|
||||||
|
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
20
docs/usage/bullet-points.md
Normal file
20
docs/usage/bullet-points.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Bullet Points
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
To make a bullet point, simply make a paragraph into a bullet point:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun("Bullet points");
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Bullet points",
|
||||||
|
bullet: {
|
||||||
|
level: 0, //How deep you want the bullet to be
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### This will produce:
|
||||||
|
|
||||||
|
- Bullet points
|
||||||
|
- Are awesome
|
61
docs/usage/change-tracking.md
Normal file
61
docs/usage/change-tracking.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Change Tracking
|
||||||
|
|
||||||
|
> Instead of adding a `TextRun` into a `Paragraph`, you can also add an `InsertedTextRun` or `DeletedTextRun` where you need to supply an `id`, `author` and `date` for the change.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo "),
|
||||||
|
new TextRun({
|
||||||
|
text: "on how to "
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "mark a text as an insertion ",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "or a deletion.",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
})
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that for a `InsertedTextRun` and `DeletedTextRun`, it is not possible to simply call it with only a text as in `new TextRun("some text")`, since the additonal fields for change tracking need to be provided. Similar to a normal `TextRun` you can add additional text properties.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo"),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "with a deletion.",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
})
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
In addtion to marking text as inserted or deleted, change tracking can also be added via the document settings. This will enable new changes to be tracked as well.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Document } from "docx";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
features: {
|
||||||
|
trackRevisions: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
22
docs/usage/convenience-functions.md
Normal file
22
docs/usage/convenience-functions.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Convenience functions
|
||||||
|
|
||||||
|
OOXML and this library mainly uses a unit called twentieths of a point or `twip` for short. a twip is a typographical measurement, defined as 1/20 of a typographical point. One twip is 1/1440 inch, or 17.64 μm. This unit is not intuitive for many users, so some functions were created to help
|
||||||
|
|
||||||
|
More info here: https://en.wikipedia.org/wiki/Twip
|
||||||
|
|
||||||
|
## Convert Inches to Twip
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { convertInchesToTwip } from "docx";
|
||||||
|
|
||||||
|
const twip = convertInchesToTwip(1); // returns 1440
|
||||||
|
const twip = convertInchesToTwip(0.5); // returns 720
|
||||||
|
```
|
||||||
|
|
||||||
|
## Convert Millimeters to Twip
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { convertMillimetersToTwip } from "docx";
|
||||||
|
|
||||||
|
const twip = convertMillimetersToTwip(50); // returns 2834
|
||||||
|
```
|
57
docs/usage/document.md
Normal file
57
docs/usage/document.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Document
|
||||||
|
|
||||||
|
> The `Document` object is the starting point of your `.docx` journey, this is the literal Word Document. You add all your content such as `Paragraphs` to this `Document`, and at the end export it however you like.
|
||||||
|
|
||||||
|
To create a new document, it is very easy:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new docx.Document();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Document properties
|
||||||
|
|
||||||
|
You can add properties to the Word document by specifying options, for example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new docx.Document({
|
||||||
|
creator: "Dolan Miu",
|
||||||
|
description: "My extremely interesting document",
|
||||||
|
title: "My Document",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Full list of options:
|
||||||
|
|
||||||
|
|
||||||
|
* creator
|
||||||
|
* description
|
||||||
|
* title
|
||||||
|
* subject
|
||||||
|
* keywords
|
||||||
|
* lastModifiedBy
|
||||||
|
* revision
|
||||||
|
* externalStyles
|
||||||
|
* styles
|
||||||
|
* numbering
|
||||||
|
* footnotes
|
||||||
|
* hyperlinks
|
||||||
|
* background
|
||||||
|
|
||||||
|
### Change background color of Document
|
||||||
|
|
||||||
|
Set the hex value in the document like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new docx.Document({
|
||||||
|
background: {
|
||||||
|
color: "C45911",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can mix and match whatever properties you want, or provide no properties.
|
||||||
|
|
||||||
|
### Units for positioning
|
||||||
|
|
||||||
|
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.
|
47
docs/usage/headers-and-footers.md
Normal file
47
docs/usage/headers-and-footers.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Headers and Footers
|
||||||
|
|
||||||
|
!> Headers and Footers requires an understanding of [Sections](usage/sections.md).
|
||||||
|
|
||||||
|
Every Section has a sections which you can define its Headers and Footers:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
headers: {
|
||||||
|
default: new Header({ // The standard default header
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
first: new Header({ // The first header
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
even: new Header({ // The header on every other page
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({ // The standard default footer
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
first: new Footer({ // The first footer
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
even: new Footer({ // The footer on every other page
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want more head
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Example showing basic header and footer
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/8-header-footer.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts_
|
||||||
|
|
||||||
|
## Multiple Headers and Footers
|
||||||
|
|
||||||
|
More headers and footers can be accomplished by creating more `Section`. New headers and footers can be set per `Section`
|
47
docs/usage/hyperlinks.md
Normal file
47
docs/usage/hyperlinks.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Hyperlinks
|
||||||
|
|
||||||
|
There are two types of hyperlinks: internal (pointing to a bookmark inside the document) and external (pointing to an external url).
|
||||||
|
|
||||||
|
## Internal
|
||||||
|
|
||||||
|
To create an internal hyperlink you need first to create a bookmark (the paragraph that will be the destination of the hyperlink) with `doc.createBookmark(anchor, text)`.
|
||||||
|
|
||||||
|
A bookmark is composed of an anchor (an identifier) and the text displayed. After creating a bookmark just add it to a paragraph with `paragraph.addBookmark(bookmark)`
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const bookmark = this.doc.createBookmark('anchorForChapter1', 'This is chapter1');
|
||||||
|
paragraph.addBookmark(bookmark);
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can create an hyperlink pointing to that bookmark with `doc.createInternalHyperLink(anchor,text)`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const link = this.doc.createInternalHyperLink('anchorForChapter1', 'This is a link to chapter1');
|
||||||
|
paragraph.addHyperLink(link);
|
||||||
|
```
|
||||||
|
|
||||||
|
## External
|
||||||
|
|
||||||
|
To create an external hyperlink you just need to specify the url and the text of the link, then add it to a paragraph with `doc.createHyperlink(url, text)`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = this.doc.createParagraph();
|
||||||
|
const link = this.doc.createHyperlink('https://docx.js.org', 'This is an external link');
|
||||||
|
paragraph.addHyperLink(link);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Styling an hyperlink
|
||||||
|
|
||||||
|
It is possible to set the style of the text of an hyperlink. This can be done applying run formatting on `TextRun` property of the hyperlink.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const link = this.doc.createHyperlink('https://docx.js.org', 'This is an external link');
|
||||||
|
link.TextRun.bold().italics()
|
||||||
|
```
|
249
docs/usage/images.md
Normal file
249
docs/usage/images.md
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
# Images
|
||||||
|
|
||||||
|
!> Images requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
To create a `floating` image on top of text:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
By default with no arguments, its an `inline` image:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
|
```
|
||||||
|
|
||||||
|
Add it into the document by adding the image into a paragraph:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [new Paragraph(image)],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Or:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [image],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
Adding images can be done in two ways:
|
||||||
|
|
||||||
|
1. Call the `createImage` method to add the image directly into the `document`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Media.addImage(doc, [IMAGE_BUFFER], [WIDTH], [HEIGHT], [POSITION_OPTIONS]);
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Create an `image` first, then add it into the `document`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const image = Media.addImage(doc, [IMAGE_BUFFER]);
|
||||||
|
doc.addSection({
|
||||||
|
children: [new Paragraph(image)],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`docx` supports `jpeg`, `jpg`, `bmp`, `gif` and `png`
|
||||||
|
|
||||||
|
## Positioning
|
||||||
|
|
||||||
|
> Positioning is the method on how to place the image on the document
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Three types of image positioning is supported:
|
||||||
|
|
||||||
|
- Floating
|
||||||
|
- Inline
|
||||||
|
|
||||||
|
By default, picture are exported as `Inline` elements.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
Pass `options` into the `[POSITION_OPTIONS]` metioned in the [Intro above](#Intro).
|
||||||
|
|
||||||
|
## Floating
|
||||||
|
|
||||||
|
To change the position the image to be on top of the text, simply add the `floating` property to the last argument. By default, the offsets are relative to the top left corner of the `page`. Offset units are in [emus](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/):
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const imageData = document.createImage(buffer, 903, 1149, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 1014400, // relative: HorizontalPositionRelativeFrom.PAGE by default
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 1014400, // relative: VerticalPositionRelativeFrom.PAGE by default
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const imageData = document.createImage(buffer, 903, 1149, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
relative: HorizontalPositionRelativeFrom.RIGHT_MARGIN,
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
relative: VerticalPositionRelativeFrom.BOTTOM_MARGIN,
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
Full options you can pass into `floating` are:
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| ------------------ | --------------------------- | -------- |
|
||||||
|
| horizontalPosition | `HorizontalPositionOptions` | Required |
|
||||||
|
| verticalPosition | `VerticalPositionOptions` | Required |
|
||||||
|
| allowOverlap | `boolean` | Optional |
|
||||||
|
| lockAnchor | `boolean` | Optional |
|
||||||
|
| behindDocument | `boolean` | Optional |
|
||||||
|
| layoutInCell | `boolean` | Optional |
|
||||||
|
| zIndex | `number` | Optional |
|
||||||
|
|
||||||
|
`HorizontalPositionOptions` are:
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| -------- | -------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
||||||
|
| relative | `HorizontalPositionRelativeFrom` | Required | `CHARACTER`, `COLUMN`, `INSIDE_MARGIN`, `LEFT_MARGIN`, `MARGIN`, `OUTSIDE_MARGIN`, `PAGE`, `RIGHT_MARGIN` |
|
||||||
|
| align | `HorizontalPositionAlign` | You can either have `align` or `offset`, not both | `CENTER`, `INSIDE`, `LEFT`, `OUTSIDE`, `RIGHT` |
|
||||||
|
| offset | `number` | You can either have `align` or `offset`, not both | `0` to `Infinity` |
|
||||||
|
|
||||||
|
`VerticalPositionOptions` are:
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| -------- | ------------------------------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
||||||
|
| relative | `VerticalPositionRelativeFrom` | Required | `BOTTOM_MARGIN`, `INSIDE_MARGIN`, `LINE`, `MARGIN`, `OUTSIDE_MARGIN`, `PAGE`, `PARAGRAPH`, `TOP_MARGIN` |
|
||||||
|
| align | `VerticalPositionAlign` | You can either have `align` or `offset`, not both | `BOTTOM`, `CENTER`, `INSIDE`, `OUTSIDE`, `TOP` |
|
||||||
|
| offset | `number` | You can either have `align` or `offset`, not both | `0` to `Infinity` |
|
||||||
|
|
||||||
|
## Wrap text
|
||||||
|
|
||||||
|
Wrapping only works for floating elements. Text will "wrap" around the floating `image`.
|
||||||
|
|
||||||
|
Add `wrap` options inside the `floating` options:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
wrap: {
|
||||||
|
type: [TextWrappingType],
|
||||||
|
side: [TextWrappingSide],
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
wrap: {
|
||||||
|
type: TextWrappingType.SQUARE,
|
||||||
|
side: TextWrappingSide.BOTH_SIDES,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Wrap options have the following properties are:
|
||||||
|
|
||||||
|
| Property | Type | Notes | Possible Values |
|
||||||
|
| -------- | ------------------ | -------- | ------------------------------------------- |
|
||||||
|
| type | `TextWrappingType` | Optional | `NONE`, `SQUARE`, `TIGHT`, `TOP_AND_BOTTOM` |
|
||||||
|
| side | `TextWrappingSide` | Optional | `BOTH_SIDES`, `LEFT`, `RIGHT`, `LARGEST` |
|
||||||
|
|
||||||
|
## Margins
|
||||||
|
|
||||||
|
Margins give some space between the text and the image. Margins [only work for floating elements](http://officeopenxml.com/drwPicInline.php). Additionally, the image must also be in wrap mode (see above).
|
||||||
|
|
||||||
|
?> Be sure to also set `wrap` in your options!
|
||||||
|
|
||||||
|
To use, add the `margins` options inside the `floating` options:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
margins: {
|
||||||
|
top: number,
|
||||||
|
bottom: number,
|
||||||
|
left: number,
|
||||||
|
right: number
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 2014400,
|
||||||
|
},
|
||||||
|
wrap: {
|
||||||
|
type: TextWrappingType.SQUARE,
|
||||||
|
side: TextWrappingSide.BOTH_SIDES,
|
||||||
|
},
|
||||||
|
margins: {
|
||||||
|
top: 201440,
|
||||||
|
bottom: 201440,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Add image to the document
|
||||||
|
|
||||||
|
Importing Images from file system path
|
||||||
|
|
||||||
|
[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_
|
||||||
|
|
||||||
|
### Add images to header and footer
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/9-images-in-header-and-footer.ts_
|
||||||
|
|
||||||
|
### Floating images
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/38-text-wrapping.ts_
|
265
docs/usage/math.md
Normal file
265
docs/usage/math.md
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
# Math
|
||||||
|
|
||||||
|
!> Math requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
1. To add math, create a `Math` object
|
||||||
|
2. Add `MathComponents` inside `Math`
|
||||||
|
3. `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below
|
||||||
|
4. Make sure to add the `Math` object inside a `Paragraph`
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2+2"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("hi")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
This will produce:
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="clippy the assistant" src="images/math-example.png" width="200">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Math Components
|
||||||
|
|
||||||
|
`MathComponents` are the unit sized building blocks of an equation in `docx`. A `MathComponent` takes in more nested `MathComponents` until you reach `MathRun`, which has no children. `MathRun` is similar to a [TextRun](usage/text.md).
|
||||||
|
|
||||||
|
### Math Run
|
||||||
|
|
||||||
|
`MathRun` is the most basic `MathComponent`.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRun("2+2");
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRun("hello");
|
||||||
|
```
|
||||||
|
|
||||||
|
An example of it being used inside `Math`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2"),
|
||||||
|
new MathRun("+"),
|
||||||
|
new MathRun("2"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Math Fraction
|
||||||
|
|
||||||
|
`MathFractions` require a `numerator` and a `demoninator`, which are both a list of `MathComponents`
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRun("1"),
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
An example of it being used inside `Math`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathText("+"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathText("= 1"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sum
|
||||||
|
|
||||||
|
A `MathComponent` for `Σ`. It can take a `superScript` and/or `subScript` as arguments to add `MathComponents` (usually limits) on the top and bottom
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSum({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
})
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Radicals
|
||||||
|
|
||||||
|
A `MathComponent` for the `√` symbol. Examples include, square root, cube root etc. There is an optional `degree` parameter to specify the number of times the radicand is multiplied by itself. For example, `3` for cube root.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
Cube root example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRadical({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathRun('+ 1'),
|
||||||
|
],
|
||||||
|
degree: [new MathRun("3")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Super Script
|
||||||
|
|
||||||
|
`MathSuperScripts` are the little numbers written to the top right of numbers or variables. It means the exponent or power if written by itself with the number or variable.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
An example with cosine:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sub Script
|
||||||
|
|
||||||
|
`MathSubScripts` are similar to `MathSuperScripts`, except the little number is written below.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("F")],
|
||||||
|
subScript: [new MathRun("n-1")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sub-Super Script
|
||||||
|
|
||||||
|
`MathSubSuperScripts` are a combination of both `MathSuperScript` and `MathSubScript`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function
|
||||||
|
|
||||||
|
`MathFunctions` are a way of describing what happens to an input variable, in order to get the output result. It takes a `name` parameter to specify the name of the function.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFunction({
|
||||||
|
name: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
children: [new MathRun("100")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Brackets
|
||||||
|
|
||||||
|
#### Square brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSquareBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Round brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRoundBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Curly brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathCurlyBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Angled brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathAngledBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
88
docs/usage/numbering.md
Normal file
88
docs/usage/numbering.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# Bullets and Numbering
|
||||||
|
|
||||||
|
`docx` is quite flexible in its bullets and numbering system, allowing
|
||||||
|
the user great freedom in how bullets and numbers are to be styled and
|
||||||
|
displayed. E.g., numbers can be shown using Arabic numerals, roman
|
||||||
|
numerals, or even ordinal words ("one", "two", "three", ...). The
|
||||||
|
format also supports re-using bullets/numbering styles throughout the
|
||||||
|
document, so that different lists using the same style need not
|
||||||
|
redefine them.
|
||||||
|
|
||||||
|
Because of this flexibility, bullets and numbering in DOCX involves a
|
||||||
|
couple of moving pieces:
|
||||||
|
|
||||||
|
1. Document-level bullets/numbering definitions (abstract)
|
||||||
|
2. Document-level bullets/numbering definitions (concrete)
|
||||||
|
3. Paragraph-level bullets/numbering selection
|
||||||
|
|
||||||
|
## Document-level bullets/numbering definitions (abstract)
|
||||||
|
|
||||||
|
Every document contains a set of abstract bullets/numbering
|
||||||
|
definitions which define the formatting and layout of paragraphs using
|
||||||
|
those bullets/numbering. An abstract numbering system defines how
|
||||||
|
bullets/numbers are to be shown for lists, including any sublists that
|
||||||
|
may be used. Thus each abstract definition includes a series of
|
||||||
|
_levels_ which form a sequence starting at 0 indicating the top-level
|
||||||
|
list look and increasing from there to descibe the sublists, then
|
||||||
|
sub-sublists, etc. Each level includes the following properties:
|
||||||
|
|
||||||
|
* **level**: This is its 0-based index in the definition stack
|
||||||
|
* **numberFormat**: This indicates how the bullet or number should be
|
||||||
|
generated. Options include `bullet` (meaning don't count), `decimal`
|
||||||
|
(arabic numerals), `upperRoman`, `lowerRoman`, `hex`, and many
|
||||||
|
more.
|
||||||
|
* **levelText**: This is a format string using the output of the
|
||||||
|
`numberFormat` function and generating a string to insert before
|
||||||
|
every item in the list. You may use `%1`, `%2`, ... to reference the
|
||||||
|
numbers from each numbering level before this one. Thus a level
|
||||||
|
text of `%d)` with a number format of `lowerLetter` would result in
|
||||||
|
the sequence "a)", "b)", ...
|
||||||
|
* and a few others, which you can see in the OXML spec section 17.9.6
|
||||||
|
|
||||||
|
## Document-level bullets/numbering defintions (concrete)
|
||||||
|
|
||||||
|
Concrete definitions are sort of like concrete subclasses of the
|
||||||
|
abstract defintions. They indicate their parent and are allowed to
|
||||||
|
override certain level definitions. Thus two lists that differ only in
|
||||||
|
how sub-sub-lists are to be displayed can share the same abstract
|
||||||
|
numbering definition and have slightly different concrete definitions.
|
||||||
|
|
||||||
|
## Paragraph-level bullets/numbering selection
|
||||||
|
|
||||||
|
In order to use a bullets/numbering definition (which must be
|
||||||
|
concrete), paragraphs need to select it, similar to applying a CSS
|
||||||
|
class to an element, using both the concrete numbering definition ID
|
||||||
|
and the level number that the paragraph should be at. Additionally, MS
|
||||||
|
Word and LibreOffice typically apply a "ListParagraph" style to
|
||||||
|
paragraphs that are being numbered.
|
||||||
|
|
||||||
|
## Using bullets/numbering in `docx`
|
||||||
|
|
||||||
|
`docx` includes a pre-defined bullet style which you can add to your
|
||||||
|
paragraphs using `para.bullets()`. If you require different bullet
|
||||||
|
styles or numbering of any kind, you'll have to use the
|
||||||
|
`docx.Numbering` class.
|
||||||
|
|
||||||
|
First you need to create a new numbering container class and use it to
|
||||||
|
create your abstract numbering style, define your levels, and create
|
||||||
|
your concrete numbering style:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const numbering = new docx.Numbering();
|
||||||
|
|
||||||
|
const abstractNum = numbering.createAbstractNumbering();
|
||||||
|
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent(720, 260));
|
||||||
|
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent(1440, 980));
|
||||||
|
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent(2160, 1700));
|
||||||
|
|
||||||
|
const concrete = numbering.createConcreteNumbering(abstractNum);
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then apply your concrete style to paragraphs using the
|
||||||
|
`setNumbering` method:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
topLevelP.setNumbering(concrete, 0);
|
||||||
|
subP.setNumbering(concrete, 1);
|
||||||
|
subSubP.setNumbering(concrete, 2);
|
||||||
|
```
|
34
docs/usage/packers.md
Normal file
34
docs/usage/packers.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Packers
|
||||||
|
|
||||||
|
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
|
||||||
|
|
||||||
|
Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF.
|
||||||
|
|
||||||
|
### Export as Buffer
|
||||||
|
|
||||||
|
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Export as a `base64` string
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Packer.toBase64String(doc).then((string) => {
|
||||||
|
console.log(string);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Export as Blob
|
||||||
|
|
||||||
|
This is useful if you want to send it as an downloadable in a browser environment.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
Packer.toBlob(doc).then((blob) => {
|
||||||
|
// saveAs from FileSaver will download the file
|
||||||
|
saveAs(blob, "example.docx");
|
||||||
|
});
|
||||||
|
```
|
66
docs/usage/page-numbers.md
Normal file
66
docs/usage/page-numbers.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Page Numbers
|
||||||
|
|
||||||
|
> This feature allows you to set page numbers on each page
|
||||||
|
|
||||||
|
?> **Note:** This feature only works on Headers and Footers
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.Header.createParagraph().addRun(new TextRun("Page Number: ").pageNumber()).addRun(new TextRun("to ").numberOfTotalPages());
|
||||||
|
```
|
||||||
|
|
||||||
|
## Current page number
|
||||||
|
|
||||||
|
To get the current page number, call the `.pageNumber()` method on a `TextRun`. Then add the newly created `TextRun` into a paragraph
|
||||||
|
|
||||||
|
```ts
|
||||||
|
pageNumber();
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const currentPageRun = new TextRun("Current Page Number: ").pageNumber();
|
||||||
|
paragraph.addRun(currentPageRun);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Total number of pages
|
||||||
|
|
||||||
|
```ts
|
||||||
|
numberOfTotalPages();
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const lastPage = new TextRun("Total Page Number: ").numberOfTotalPages();
|
||||||
|
paragraph.addRun(lastPage);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Both
|
||||||
|
|
||||||
|
You can combine the two to get "Page 2 of 10" effect:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const currentPageRun = new TextRun("Page ").pageNumber();
|
||||||
|
const lastPage = new TextRun("of ").numberOfTotalPages();
|
||||||
|
|
||||||
|
paragraph.addRun(currentPageRun);
|
||||||
|
paragraph.addRun(lastPage);
|
||||||
|
```
|
||||||
|
|
||||||
|
Or:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.Header.createParagraph().addRun(new TextRun("Page ").pageNumber()).addRun(new TextRun("of ").numberOfTotalPages());
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Simple Example
|
||||||
|
|
||||||
|
Adding page numbers to Header and Footer
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/39-page-numbers.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/39-page-numbers.ts_
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user