Compare commits
484 Commits
Author | SHA1 | Date | |
---|---|---|---|
5cf534ad26 | |||
d53cdb0558 | |||
212adbbffb | |||
99ab2f0ef5 | |||
a8201b2658 | |||
f13e676c3b | |||
61b01836bc | |||
2ee918b845 | |||
e9579d75c4 | |||
97824f1bb5 | |||
884c134b25 | |||
4f3cb49076 | |||
152285ed5a | |||
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 | |||
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 | |||
5ecdb48d43 | |||
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 | |||
97f76fb62c | |||
3508fd97ec | |||
90f6f68693 | |||
733775d3b9 | |||
f3aa6a9203 | |||
ffdcc7baca | |||
a1e20f4c9a | |||
048ae6a58c | |||
fafa54e4c9 | |||
60dbb32e9e | |||
52b07fd9cb | |||
8ec5bc05e0 | |||
6e0c12afb3 | |||
466e880bfc | |||
0a8feca6ab | |||
f2b50478bf | |||
fc71ebdfef | |||
10114bb12d | |||
e6d4741955 | |||
4d7387524c | |||
5fe4405d76 | |||
79dffc873a | |||
26ee12759c | |||
2e00634bc4 | |||
d63e6bf6b1 | |||
a95366e54e | |||
1c376abeb6 | |||
353d888abd | |||
b6bd532295 | |||
c5b004166d | |||
2f43600daf | |||
b39c7ce323 | |||
5b00279996 | |||
d1d1e01aff | |||
980bc597e2 | |||
a05c5edd49 | |||
985452f5f4 | |||
482674b3b3 | |||
fcbfed9068 | |||
a9167b4809 | |||
f1b176670c | |||
11ce9a5206 | |||
385ad92331 | |||
571f8b526b | |||
7688aa99f6 | |||
4994bca34c | |||
1a3603dbfb | |||
e382dbff84 | |||
e08be3d7a4 | |||
03c4190c2c | |||
010fde6258 |
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']
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -52,7 +52,6 @@ docs/.nojekyll
|
|||||||
.idea
|
.idea
|
||||||
|
|
||||||
# Lock files
|
# Lock files
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
@ -60,3 +59,6 @@ My Document.docx
|
|||||||
|
|
||||||
# Temporary folder
|
# Temporary folder
|
||||||
tmp
|
tmp
|
||||||
|
|
||||||
|
# nyc
|
||||||
|
.nyc_output
|
||||||
|
25
.nycrc
Normal file
25
.nycrc
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"check-coverage": true,
|
||||||
|
"lines": 93.53,
|
||||||
|
"functions": 89.63,
|
||||||
|
"branches": 88.57,
|
||||||
|
"statements": 93.34,
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"src/**/*.spec.ts"
|
||||||
|
],
|
||||||
|
"reporter": [
|
||||||
|
"lcov",
|
||||||
|
"text",
|
||||||
|
"json"
|
||||||
|
],
|
||||||
|
"extension": [
|
||||||
|
".ts"
|
||||||
|
],
|
||||||
|
"cache": true,
|
||||||
|
"all": true,
|
||||||
|
"instrument": false,
|
||||||
|
"sourceMap": true
|
||||||
|
}
|
65
.travis.yml
65
.travis.yml
@ -3,41 +3,56 @@ node_js:
|
|||||||
- 9
|
- 9
|
||||||
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
|
||||||
- npm run ts-node -- ./demo/demo1.ts
|
- npm run ts-node -- ./demo/1-basic.ts
|
||||||
- npm run ts-node -- ./demo/demo2.ts
|
- npm run e2e "My Document.docx"
|
||||||
- npm run ts-node -- ./demo/demo3.ts
|
- npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||||
- npm run ts-node -- ./demo/demo4.ts
|
- npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||||
- npm run ts-node -- ./demo/demo5.ts
|
- npm run ts-node -- ./demo/4-basic-table.ts
|
||||||
- npm run ts-node -- ./demo/demo6.ts
|
- npm run ts-node -- ./demo/5-images.ts
|
||||||
- npm run ts-node -- ./demo/demo7.ts
|
- npm run ts-node -- ./demo/6-page-borders.ts
|
||||||
- npm run ts-node -- ./demo/demo8.ts
|
- npm run ts-node -- ./demo/7-landscape.ts
|
||||||
- npm run ts-node -- ./demo/demo9.ts
|
- npm run ts-node -- ./demo/8-header-footer.ts
|
||||||
- npm run ts-node -- ./demo/demo10.ts
|
- npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||||
- npm run ts-node -- ./demo/demo11.ts
|
- npm run ts-node -- ./demo/10-my-cv.ts
|
||||||
- npm run ts-node -- ./demo/demo12.ts
|
- npm run e2e "My Document.docx"
|
||||||
- npm run ts-node -- ./demo/demo13.ts
|
- npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||||
- npm run ts-node -- ./demo/demo14.ts
|
- npm run ts-node -- ./demo/12-scaling-images.ts
|
||||||
- npm run ts-node -- ./demo/demo15.ts
|
- npm run ts-node -- ./demo/13-xml-styles.ts
|
||||||
- npm run ts-node -- ./demo/demo16.ts
|
- npm run ts-node -- ./demo/14-page-numbers.ts
|
||||||
- npm run ts-node -- ./demo/demo17.ts
|
- npm run ts-node -- ./demo/15-page-break-before.ts
|
||||||
- npm run ts-node -- ./demo/demo18.ts
|
- npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||||
- npm run ts-node -- ./demo/demo19.ts
|
- npm run ts-node -- ./demo/17-footnotes.ts
|
||||||
- npm run ts-node -- ./demo/demo20.ts
|
- npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||||
- npm run ts-node -- ./demo/demo21.ts
|
- npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
- npm run ts-node -- ./demo/demo22.ts
|
- npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
- npm run ts-node -- ./demo/demo23.ts
|
- npm run ts-node -- ./demo/21-bookmarks.ts
|
||||||
- npm run ts-node -- ./demo/demo24.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:
|
||||||
- npm run typedoc
|
- npm run typedoc
|
||||||
- echo "docx.js.org" > docs/.nojekyll
|
- echo "docx.js.org" > docs/.nojekyll
|
||||||
- echo "docx.js.org" > docs/CNAME
|
- echo "docx.js.org" > docs/CNAME
|
||||||
|
- codecov
|
||||||
deploy:
|
deploy:
|
||||||
provider: pages
|
provider: pages
|
||||||
skip-cleanup: true
|
skip-cleanup: true
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
34
README.md
34
README.md
@ -15,20 +15,25 @@
|
|||||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||||
[![PRs Welcome][pr-image]][pr-url]
|
[![PRs Welcome][pr-image]][pr-url]
|
||||||
|
[![codecov][codecov-image]][codecov-url]
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://i.imgur.com/H5FA1Qy.gif" alt="drawing" width="800"/>
|
<img src="https://i.imgur.com/TCH0YzD.png" alt="drawing" width="800"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Demo
|
# Demo
|
||||||
|
|
||||||
## Browser
|
## Browser
|
||||||
|
|
||||||
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment.
|
Here are examples of `docx` being used with basic `HTML/JS` in a browser environment:
|
||||||
|
|
||||||
* https://codepen.io/anon/pen/dqoVgQ
|
* https://codepen.io/anon/pen/dqoVgQ
|
||||||
* https://jsfiddle.net/3xhezb5w/2
|
* https://jsfiddle.net/3xhezb5w/2
|
||||||
|
|
||||||
|
Here is an example of `docx` working in `Angular`:
|
||||||
|
|
||||||
|
* https://stackblitz.com/edit/angular-afvxtz
|
||||||
|
|
||||||
## Node
|
## Node
|
||||||
|
|
||||||
Press `endpoint` on the `RunKit` website:
|
Press `endpoint` on the `RunKit` website:
|
||||||
@ -59,8 +64,27 @@ Check the `examples` section in the [documentation](https://docx.js.org/#/exampl
|
|||||||
|
|
||||||
Read the contribution guidelines [here](https://docx.js.org/#/contribution-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/)
|
||||||
|
|
||||||
|
|
||||||
|
...and many more!
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
[![patreon][patreon-image]][patreon-url]
|
||||||
|
[![browserstack][browserstack-image]][browserstack-url]
|
||||||
|
|
||||||
Made with 💖
|
Made with 💖
|
||||||
|
|
||||||
[npm-image]: https://badge.fury.io/js/docx.svg
|
[npm-image]: https://badge.fury.io/js/docx.svg
|
||||||
@ -77,3 +101,9 @@ Made with 💖
|
|||||||
[gitter-url]: https://gitter.im/docx-lib/Lobby
|
[gitter-url]: https://gitter.im/docx-lib/Lobby
|
||||||
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
[pr-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
||||||
[pr-url]: http://makeapullrequest.com
|
[pr-url]: http://makeapullrequest.com
|
||||||
|
[codecov-image]: https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg
|
||||||
|
[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);
|
||||||
|
});
|
@ -1,7 +1,7 @@
|
|||||||
// Add images to header and footer
|
// Generate a CV
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||||
|
|
||||||
// tslint:disable:no-shadowed-variable
|
// tslint:disable:no-shadowed-variable
|
||||||
|
|
||||||
@ -127,150 +127,168 @@ const achievements = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
class DocumentCreator {
|
class DocumentCreator {
|
||||||
public create(data: object[]): Document {
|
// tslint:disable-next-line: typedef
|
||||||
// tslint:disable-next-line:no-any
|
public create([experiences, educations, skills, achivements]): Document {
|
||||||
const experiences = data[0] as any[];
|
|
||||||
// tslint:disable-next-line:no-any
|
|
||||||
const educations = data[1] as any[];
|
|
||||||
const skills = data[2] as object[];
|
|
||||||
const achivements = data[3] as object[];
|
|
||||||
const document = new Document();
|
const document = new Document();
|
||||||
document.addParagraph(new Paragraph("Dolan Miu").title());
|
|
||||||
|
|
||||||
document.addParagraph(this.createContactInfo(PHONE_NUMBER, PROFILE_URL, EMAIL));
|
document.addSection({
|
||||||
document.addParagraph(this.createHeading("Education"));
|
children: [
|
||||||
|
new Paragraph({
|
||||||
for (const education of educations) {
|
text: "Dolan Miu",
|
||||||
document.addParagraph(
|
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}`),
|
this.createInstitutionHeader(education.schoolName, `${education.startDate.year} - ${education.endDate.year}`),
|
||||||
);
|
);
|
||||||
document.addParagraph(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
|
arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
|
||||||
|
|
||||||
const bulletPoints = this.splitParagraphIntoBullets(education.notes);
|
const bulletPoints = this.splitParagraphIntoBullets(education.notes);
|
||||||
bulletPoints.forEach((bulletPoint) => {
|
bulletPoints.forEach((bulletPoint) => {
|
||||||
document.addParagraph(this.createBullet(bulletPoint));
|
arr.push(this.createBullet(bulletPoint));
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
document.addParagraph(this.createHeading("Experience"));
|
return arr;
|
||||||
|
})
|
||||||
|
.reduce((prev, curr) => prev.concat(curr), []),
|
||||||
|
this.createHeading("Experience"),
|
||||||
|
...experiences
|
||||||
|
.map((position) => {
|
||||||
|
const arr: Paragraph[] = [];
|
||||||
|
|
||||||
for (const position of experiences) {
|
arr.push(
|
||||||
document.addParagraph(
|
|
||||||
this.createInstitutionHeader(
|
this.createInstitutionHeader(
|
||||||
position.company.name,
|
position.company.name,
|
||||||
this.createPositionDateText(position.startDate, position.endDate, position.isCurrent),
|
this.createPositionDateText(position.startDate, position.endDate, position.isCurrent),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
document.addParagraph(this.createRoleText(position.title));
|
arr.push(this.createRoleText(position.title));
|
||||||
|
|
||||||
const bulletPoints = this.splitParagraphIntoBullets(position.summary);
|
const bulletPoints = this.splitParagraphIntoBullets(position.summary);
|
||||||
|
|
||||||
bulletPoints.forEach((bulletPoint) => {
|
bulletPoints.forEach((bulletPoint) => {
|
||||||
document.addParagraph(this.createBullet(bulletPoint));
|
arr.push(this.createBullet(bulletPoint));
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
document.addParagraph(this.createHeading("Skills, Achievements and Interests"));
|
return arr;
|
||||||
|
})
|
||||||
document.addParagraph(this.createSubHeading("Skills"));
|
.reduce((prev, curr) => prev.concat(curr), []),
|
||||||
document.addParagraph(this.createSkillList(skills));
|
this.createHeading("Skills, Achievements and Interests"),
|
||||||
|
this.createSubHeading("Skills"),
|
||||||
document.addParagraph(this.createSubHeading("Achievements"));
|
this.createSkillList(skills),
|
||||||
|
this.createSubHeading("Achievements"),
|
||||||
for (const achievementParagraph of this.createAchivementsList(achivements)) {
|
...this.createAchivementsList(achivements),
|
||||||
document.addParagraph(achievementParagraph);
|
this.createSubHeading("Interests"),
|
||||||
}
|
this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."),
|
||||||
|
this.createHeading("References"),
|
||||||
document.addParagraph(this.createSubHeading("Interests"));
|
|
||||||
|
|
||||||
document.addParagraph(this.createInterests("Programming, Technology, Music Production, Web Design, 3D Modelling, Dancing."));
|
|
||||||
|
|
||||||
document.addParagraph(this.createHeading("References"));
|
|
||||||
|
|
||||||
document.addParagraph(
|
|
||||||
new Paragraph(
|
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",
|
"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"),
|
||||||
document.addParagraph(new Paragraph("More references upon request"));
|
new Paragraph({
|
||||||
document.addParagraph(
|
text: "This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
|
||||||
new Paragraph(
|
alignment: AlignmentType.CENTER,
|
||||||
"This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
|
}),
|
||||||
).center(),
|
],
|
||||||
);
|
});
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createContactInfo(phoneNumber: string, profileUrl: string, email: string): Paragraph {
|
public createContactInfo(phoneNumber: string, profileUrl: string, email: string): Paragraph {
|
||||||
const paragraph = new Paragraph().center();
|
return new Paragraph({
|
||||||
const contactInfo = new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`);
|
alignment: AlignmentType.CENTER,
|
||||||
const address = new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break();
|
children: [
|
||||||
|
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
|
||||||
paragraph.addRun(contactInfo);
|
new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break(),
|
||||||
paragraph.addRun(address);
|
],
|
||||||
|
});
|
||||||
return paragraph;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public createHeading(text: string): Paragraph {
|
public createHeading(text: string): Paragraph {
|
||||||
return new Paragraph(text).heading1().thematicBreak();
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
thematicBreak: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createSubHeading(text: string): Paragraph {
|
public createSubHeading(text: string): Paragraph {
|
||||||
return new Paragraph(text).heading2();
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createInstitutionHeader(institutionName: string, dateText: string): Paragraph {
|
public createInstitutionHeader(institutionName: string, dateText: string): Paragraph {
|
||||||
const paragraph = new Paragraph().maxRightTabStop();
|
return new Paragraph({
|
||||||
const institution = new TextRun(institutionName).bold();
|
tabStops: [
|
||||||
const date = new TextRun(dateText).tab().bold();
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
paragraph.addRun(institution);
|
position: TabStopPosition.MAX,
|
||||||
paragraph.addRun(date);
|
},
|
||||||
|
],
|
||||||
return paragraph;
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: institutionName,
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: `\t${dateText}`,
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createRoleText(roleText: string): Paragraph {
|
public createRoleText(roleText: string): Paragraph {
|
||||||
const paragraph = new Paragraph();
|
return new Paragraph({
|
||||||
const role = new TextRun(roleText).italic();
|
children: [
|
||||||
|
new TextRun({
|
||||||
paragraph.addRun(role);
|
text: roleText,
|
||||||
|
italics: true,
|
||||||
return paragraph;
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createBullet(text: string): Paragraph {
|
public createBullet(text: string): Paragraph {
|
||||||
return new Paragraph(text).bullet();
|
return new Paragraph({
|
||||||
|
text: text,
|
||||||
|
bullet: {
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
public createSkillList(skills: any[]): Paragraph {
|
public createSkillList(skills: any[]): Paragraph {
|
||||||
const paragraph = new Paragraph();
|
return new Paragraph({
|
||||||
const skillConcat = skills.map((skill) => skill.name).join(", ") + ".";
|
children: [new TextRun(skills.map((skill) => skill.name).join(", ") + ".")],
|
||||||
|
});
|
||||||
paragraph.addRun(new TextRun(skillConcat));
|
|
||||||
|
|
||||||
return paragraph;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
public createAchivementsList(achivements: any[]): Paragraph[] {
|
public createAchivementsList(achivements: any[]): Paragraph[] {
|
||||||
const arr: Paragraph[] = [];
|
return achivements.map(
|
||||||
|
(achievement) =>
|
||||||
for (const achievement of achivements) {
|
new Paragraph({
|
||||||
const paragraph = new Paragraph(achievement.name).bullet();
|
text: achievement.name,
|
||||||
arr.push(paragraph);
|
bullet: {
|
||||||
}
|
level: 0,
|
||||||
|
},
|
||||||
return arr;
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createInterests(interests: string): Paragraph {
|
public createInterests(interests: string): Paragraph {
|
||||||
const paragraph = new Paragraph();
|
return new Paragraph({
|
||||||
|
children: [new TextRun(interests)],
|
||||||
paragraph.addRun(new TextRun(interests));
|
});
|
||||||
return paragraph;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public splitParagraphIntoBullets(text: string): string[] {
|
public splitParagraphIntoBullets(text: string): string[] {
|
||||||
@ -321,8 +339,6 @@ const documentCreator = new DocumentCreator();
|
|||||||
|
|
||||||
const doc = documentCreator.create([experiences, education, skills, achievements]);
|
const doc = documentCreator.create([experiences, education, skills, achievements]);
|
||||||
|
|
||||||
const packer = new Packer();
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
});
|
});
|
263
demo/11-declaritive-styles-2.ts
Normal file
263
demo/11-declaritive-styles-2.ts
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
// Setting styles with JavaScript configuration
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
Document,
|
||||||
|
Footer,
|
||||||
|
HeadingLevel,
|
||||||
|
Media,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
TabStopPosition,
|
||||||
|
UnderlineType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "Heading1",
|
||||||
|
name: "Heading 1",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 52,
|
||||||
|
bold: true,
|
||||||
|
color: "000000",
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.SINGLE,
|
||||||
|
color: "000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
spacing: { line: 340 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "Heading2",
|
||||||
|
name: "Heading 2",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 340 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "Heading3",
|
||||||
|
name: "Heading 3",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "Heading4",
|
||||||
|
name: "Heading 4",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
font: "Calibri",
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.JUSTIFIED,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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: 720 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "wellSpaced",
|
||||||
|
name: "Well Spaced",
|
||||||
|
basedOn: "Normal",
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ListParagraph",
|
||||||
|
name: "List Paragraph",
|
||||||
|
basedOn: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
@ -5,14 +5,16 @@ import { Document, Packer, Paragraph } from "../build";
|
|||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document();
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
doc.addSection({
|
||||||
const paragraph2 = new Paragraph("Hello World on another page").pageBreakBefore();
|
children: [
|
||||||
|
new Paragraph("Hello World"),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World on another page",
|
||||||
|
pageBreakBefore: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
doc.addParagraph(paragraph2);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", 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);
|
||||||
|
});
|
@ -1,17 +1,22 @@
|
|||||||
// Insert image from a buffer
|
// Insert image from a buffer
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer } from "../build";
|
import { Document, Media, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document();
|
||||||
|
|
||||||
const imageBase64Data = `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`;
|
const imageBase64Data = `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`;
|
||||||
|
|
||||||
// doc.createImage(Buffer.from(imageBase64Data, 'base64'));
|
const image = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
||||||
doc.createImage(Buffer.from(imageBase64Data, "base64"), 100, 100);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [image],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("My Document.docx", 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);
|
||||||
|
});
|
174
demo/2-declaritive-styles.ts
Normal file
174
demo/2-declaritive-styles.ts
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
// 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, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
creator: "Clippy",
|
||||||
|
title: "Sample Document",
|
||||||
|
description: "A brief example of using docx",
|
||||||
|
styles: {
|
||||||
|
paragraphStyles: [
|
||||||
|
{
|
||||||
|
id: "Heading1",
|
||||||
|
name: "Heading 1",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
size: 28,
|
||||||
|
bold: true,
|
||||||
|
italics: true,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
after: 120,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "Heading2",
|
||||||
|
name: "Heading 2",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
size: 26,
|
||||||
|
bold: true,
|
||||||
|
underline: {
|
||||||
|
type: UnderlineType.DOUBLE,
|
||||||
|
color: "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
before: 240,
|
||||||
|
after: 120,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "aside",
|
||||||
|
name: "Aside",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
run: {
|
||||||
|
color: "999999",
|
||||||
|
italics: true,
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
indent: {
|
||||||
|
left: 720,
|
||||||
|
},
|
||||||
|
spacing: {
|
||||||
|
line: 276,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "wellSpaced",
|
||||||
|
name: "Well Spaced",
|
||||||
|
basedOn: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
paragraph: {
|
||||||
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ListParagraph",
|
||||||
|
name: "List Paragraph",
|
||||||
|
basedOn: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "lowerLetter",
|
||||||
|
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 back to normal.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
@ -1,37 +1,40 @@
|
|||||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer } from "../build";
|
import { Bookmark, Document, HeadingLevel, HyperlinkRef, HyperlinkType, Packer, PageBreak, Paragraph } from "../build";
|
||||||
|
|
||||||
const loremIpsum =
|
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.";
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
creator: "Clippy",
|
creator: "Clippy",
|
||||||
title: "Sample Document",
|
title: "Sample Document",
|
||||||
description: "A brief example of using docx with bookmarks and internal hyperlinks",
|
description: "A brief example of using docx with bookmarks and internal hyperlinks",
|
||||||
|
hyperlinks: {
|
||||||
|
myAnchorId: {
|
||||||
|
text: "Hyperlink",
|
||||||
|
type: HyperlinkType.INTERNAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const anchorId = "anchorID";
|
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")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
// First create the bookmark
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
const bookmark = doc.createBookmark(anchorId, "Lorem Ipsum");
|
|
||||||
// That has header styling
|
|
||||||
doc
|
|
||||||
.createParagraph()
|
|
||||||
.addBookmark(bookmark)
|
|
||||||
.heading1();
|
|
||||||
doc.createParagraph("\n");
|
|
||||||
|
|
||||||
doc.createParagraph(loremIpsum);
|
|
||||||
doc.createParagraph().pageBreak();
|
|
||||||
|
|
||||||
// Now the link back up to the bookmark
|
|
||||||
const hyperlink = doc.createInternalHyperLink(anchorId, `Click me!`);
|
|
||||||
doc.createParagraph().addHyperLink(hyperlink);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", 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);
|
||||||
|
});
|
@ -1,34 +1,32 @@
|
|||||||
// This demo adds an image to the Media cache, and then insert to the document afterwards
|
// 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 from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Media, Packer, Paragraph } from "../build";
|
import { Document, Media, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document();
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
||||||
doc.addParagraph(paragraph);
|
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/dog.png"));
|
||||||
|
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"));
|
||||||
const image = Media.addImage(doc, "./demo/images/image1.jpeg");
|
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"));
|
||||||
const image2 = Media.addImage(doc, "./demo/images/dog.png");
|
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
const image3 = Media.addImage(doc, "./demo/images/cat.jpg");
|
|
||||||
const image4 = Media.addImage(doc, "./demo/images/parrots.bmp");
|
|
||||||
const image5 = Media.addImage(doc, "./demo/images/pizza.gif");
|
|
||||||
|
|
||||||
const imageBase64Data = `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`;
|
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);
|
const image6 = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
||||||
|
|
||||||
// I am adding an image to the paragraph rather than the document to make the image inline
|
doc.addSection({
|
||||||
paragraph.addImage(image5);
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World"), image5],
|
||||||
|
}),
|
||||||
|
new Paragraph(image),
|
||||||
|
new Paragraph(image2),
|
||||||
|
new Paragraph(image3),
|
||||||
|
new Paragraph(image4),
|
||||||
|
new Paragraph(image6),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
doc.addImage(image);
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
doc.addImage(image2);
|
|
||||||
doc.addImage(image3);
|
|
||||||
doc.addImage(image4);
|
|
||||||
doc.addImage(image5);
|
|
||||||
doc.addImage(image6);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", 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, 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: 720,
|
||||||
|
},
|
||||||
|
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);
|
||||||
|
});
|
117
demo/29-numbered-lists.ts
Normal file
117
demo/29-numbered-lists.ts
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// Numbered lists
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "upperRoman",
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 720, hanging: 260 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-crazy-reference",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "decimal",
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 720, hanging: 260 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-number-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,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
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, Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
reference: "my-crazy-numbering",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: "upperRoman",
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 720, hanging: 260 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: "decimal",
|
||||||
|
text: "%2.",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 1440, hanging: 980 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 2,
|
||||||
|
format: "lowerLetter",
|
||||||
|
text: "%3)",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 2160, hanging: 1700 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 3,
|
||||||
|
format: "upperLetter",
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
52
demo/31-tables.ts
Normal file
52
demo/31-tables.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// 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 } 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 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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
234
demo/32-merge-and-shade-table-cells.ts
Normal file
234
demo/32-merge-and-shade-table-cells.ts
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
// 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, 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: 1000,
|
||||||
|
bottom: 1000,
|
||||||
|
left: 1000,
|
||||||
|
right: 1000,
|
||||||
|
},
|
||||||
|
columnSpan: 3,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 100,
|
||||||
|
type: WidthType.AUTO,
|
||||||
|
},
|
||||||
|
columnWidths: [1000, 1000, 1000],
|
||||||
|
});
|
||||||
|
|
||||||
|
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: 7000,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
margins: {
|
||||||
|
top: 400,
|
||||||
|
bottom: 400,
|
||||||
|
right: 400,
|
||||||
|
left: 400,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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 TableCell({
|
||||||
|
children: [new Paragraph("1,2")],
|
||||||
|
rowSpan: 2,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
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"),
|
||||||
|
table4,
|
||||||
|
new Paragraph("More Merging columns"),
|
||||||
|
table5,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
26
demo/35-hyperlinks.ts
Normal file
26
demo/35-hyperlinks.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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 } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
hyperlinks: {
|
||||||
|
myCoolLink: {
|
||||||
|
link: "http://www.example.com",
|
||||||
|
text: "Hyperlink",
|
||||||
|
type: HyperlinkType.EXTERNAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new HyperlinkRef("myCoolLink")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
39
demo/46-shading-text.ts
Normal file
39
demo/46-shading-text.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
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);
|
||||||
|
});
|
37
demo/49-table-borders.ts
Normal file
37
demo/49-table-borders.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Add custom borders to the table itself
|
||||||
|
// 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 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);
|
||||||
|
});
|
62
demo/5-images.ts
Normal file
62
demo/5-images.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// 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: {
|
||||||
|
horizontalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
verticalPosition: {
|
||||||
|
offset: 1014400,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, {
|
||||||
|
floating: {
|
||||||
|
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);
|
||||||
|
});
|
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);
|
||||||
|
});
|
@ -3,16 +3,15 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document(undefined, {
|
const doc = new Document();
|
||||||
|
|
||||||
|
doc.addSection({
|
||||||
|
size: {
|
||||||
orientation: PageOrientation.LANDSCAPE,
|
orientation: PageOrientation.LANDSCAPE,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
});
|
});
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", 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);
|
||||||
|
});
|
@ -1,39 +1,45 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script src="../build/index.js"></script>
|
<script src="../build/index.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DOCX browser Word document generation</h1>
|
<h1>DOCX browser Word document generation</h1>
|
||||||
|
|
||||||
<button type="button" onclick="generate()">Click to generate document</button>
|
<button type="button" onclick="generate()">Click to generate document</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function generate() {
|
function generate() {
|
||||||
const doc = new Document();
|
const doc = new docx.Document();
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
doc.addSection({
|
||||||
const institutionText = new TextRun("Foo Bar").bold();
|
children: [
|
||||||
const dateText = new TextRun("Github is the best").tab().bold();
|
new docx.Paragraph({
|
||||||
paragraph.addRun(institutionText);
|
children: [
|
||||||
paragraph.addRun(dateText);
|
new docx.TextRun("Hello World"),
|
||||||
|
new docx.TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new docx.TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBlob(doc).then(blob => {
|
docx.Packer.toBlob(doc).then((blob) => {
|
||||||
console.log(blob);
|
console.log(blob);
|
||||||
saveAs(blob, "example.docx");
|
saveAs(blob, "example.docx");
|
||||||
console.log("Document created successfully");
|
console.log("Document created successfully");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
|
||||||
const institutionText = new TextRun("Foo Bar").bold();
|
|
||||||
const dateText = new TextRun("Github is the best").tab().bold();
|
|
||||||
paragraph.addRun(institutionText);
|
|
||||||
paragraph.addRun(dateText);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
141
demo/demo11.ts
141
demo/demo11.ts
@ -1,141 +0,0 @@
|
|||||||
// Setting styles with JavaScript configuration
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, Packer, Paragraph, Table } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document(undefined, {
|
|
||||||
top: 700,
|
|
||||||
right: 700,
|
|
||||||
bottom: 700,
|
|
||||||
left: 700,
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("Heading1", "Heading 1")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.quickFormat()
|
|
||||||
.font("Calibri")
|
|
||||||
.size(52)
|
|
||||||
.center()
|
|
||||||
.bold()
|
|
||||||
.color("000000")
|
|
||||||
.spacing({ line: 340 })
|
|
||||||
.underline("single", "000000");
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("Heading2", "Heading 2")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.font("Calibri")
|
|
||||||
.quickFormat()
|
|
||||||
.size(26)
|
|
||||||
.bold()
|
|
||||||
.spacing({ line: 340 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("Heading3", "Heading 3")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.font("Calibri")
|
|
||||||
.quickFormat()
|
|
||||||
.size(26)
|
|
||||||
.bold()
|
|
||||||
.spacing({ line: 276 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("Heading4", "Heading 4")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.justified()
|
|
||||||
.font("Calibri")
|
|
||||||
.size(26)
|
|
||||||
.bold();
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("normalPara", "Normal Para")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.font("Calibri")
|
|
||||||
.quickFormat()
|
|
||||||
.leftTabStop(453.543307087)
|
|
||||||
.maxRightTabStop()
|
|
||||||
.size(26)
|
|
||||||
.spacing({ line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("normalPara2", "Normal Para2")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.quickFormat()
|
|
||||||
.font("Calibri")
|
|
||||||
.size(26)
|
|
||||||
.justified()
|
|
||||||
.spacing({ line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("aside", "Aside")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.color("999999")
|
|
||||||
.italics()
|
|
||||||
.indent({ left: 720 })
|
|
||||||
.spacing({ line: 276 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("wellSpaced", "Well Spaced")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.spacing({ line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("ListParagraph", "List Paragraph")
|
|
||||||
.quickFormat()
|
|
||||||
.basedOn("Normal");
|
|
||||||
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
doc
|
|
||||||
.createParagraph("HEADING")
|
|
||||||
.heading1()
|
|
||||||
.center();
|
|
||||||
|
|
||||||
doc.Footer.createParagraph("1")
|
|
||||||
.style("normalPara")
|
|
||||||
.right();
|
|
||||||
|
|
||||||
doc.createParagraph("Ref. :").style("normalPara");
|
|
||||||
doc.createParagraph("Date :").style("normalPara");
|
|
||||||
|
|
||||||
doc.createParagraph("To,").style("normalPara");
|
|
||||||
doc.createParagraph("The Superindenting Engineer,(O &M)").style("normalPara");
|
|
||||||
|
|
||||||
doc.createParagraph("Sub : ").style("normalPara");
|
|
||||||
|
|
||||||
doc.createParagraph("Ref. : ").style("normalPara");
|
|
||||||
|
|
||||||
doc.createParagraph("Sir,").style("normalPara");
|
|
||||||
|
|
||||||
doc.createParagraph("BRIEF DESCRIPTION").style("normalPara");
|
|
||||||
|
|
||||||
const table = new Table(4, 4);
|
|
||||||
table
|
|
||||||
.getRow(0)
|
|
||||||
.getCell(0)
|
|
||||||
.addContent(new Paragraph("Pole No."));
|
|
||||||
// table.Properties.width = 10000;
|
|
||||||
doc.addTable(table);
|
|
||||||
|
|
||||||
const arrboth = [
|
|
||||||
{
|
|
||||||
image: "./demo/images/pizza.gif",
|
|
||||||
comment: "Test",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
image: "./demo/images/pizza.gif",
|
|
||||||
comment: "Test 2",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
arrboth.forEach((item) => {
|
|
||||||
const para = doc.createParagraph();
|
|
||||||
para.addImage(doc.createImage(fs.readFileSync(item.image)));
|
|
||||||
// para.Properties.width = 60;
|
|
||||||
// para.Properties.height = 90;
|
|
||||||
doc.createParagraph(item.comment).style("normalPara2");
|
|
||||||
});
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
// Scaling images
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const image = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
const image2 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
const image3 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
const image4 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
image.scale(0.5);
|
|
||||||
image2.scale(1);
|
|
||||||
image3.scale(2.5);
|
|
||||||
image4.scale(4);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,28 +0,0 @@
|
|||||||
// 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, Packer, Paragraph } from "../build";
|
|
||||||
|
|
||||||
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
|
||||||
const doc = new Document({
|
|
||||||
title: "Title",
|
|
||||||
externalStyles: styles,
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.createParagraph("Cool Heading Text").heading1();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph('This is a custom named style from the template "MyFancyStyle"');
|
|
||||||
paragraph.style("MyFancyStyle");
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
doc.createParagraph("Some normal text");
|
|
||||||
|
|
||||||
doc.createParagraph("MyFancyStyle again").style("MyFancyStyle");
|
|
||||||
paragraph.style("MyFancyStyle");
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,28 +0,0 @@
|
|||||||
// Page numbers
|
|
||||||
// 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.createParagraph("First Page").pageBreak();
|
|
||||||
doc.createParagraph("Second Page");
|
|
||||||
|
|
||||||
const pageNumber = new TextRun("Page ").pageNumber();
|
|
||||||
|
|
||||||
const pageoneheader = new Paragraph("First Page Header ").right();
|
|
||||||
|
|
||||||
pageoneheader.addRun(pageNumber);
|
|
||||||
const firstPageHeader = doc.createFirstPageHeader();
|
|
||||||
firstPageHeader.addParagraph(pageoneheader);
|
|
||||||
|
|
||||||
const pagetwoheader = new Paragraph("My Title ").right();
|
|
||||||
|
|
||||||
pagetwoheader.addRun(pageNumber);
|
|
||||||
doc.Header.addParagraph(pagetwoheader);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,40 +0,0 @@
|
|||||||
// Multiple sections and headers
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World").pageBreak();
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const header = doc.createHeader();
|
|
||||||
header.createParagraph("Header on another page");
|
|
||||||
const footer = doc.createFooter();
|
|
||||||
footer.createParagraph("Footer on another page");
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headerId: header.Header.ReferenceId,
|
|
||||||
footerId: footer.Footer.ReferenceId,
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.createParagraph("hello");
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headerId: header.Header.ReferenceId,
|
|
||||||
footerId: footer.Footer.ReferenceId,
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
orientation: PageOrientation.LANDSCAPE,
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.createParagraph("hello in landscape");
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// Footnotes
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World").referenceFootnote(1);
|
|
||||||
const paragraph2 = new Paragraph("Hello World").referenceFootnote(2);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
doc.addParagraph(paragraph2);
|
|
||||||
|
|
||||||
doc.createFootnote(new Paragraph("Test"));
|
|
||||||
doc.createFootnote(new Paragraph("My amazing reference"));
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,20 +0,0 @@
|
|||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
|
||||||
const institutionText = new TextRun("Foo").bold();
|
|
||||||
const dateText = new TextRun("Bar").tab().bold();
|
|
||||||
paragraph.addRun(institutionText);
|
|
||||||
paragraph.addRun(dateText);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBase64String(doc).then((str) => {
|
|
||||||
fs.writeFileSync("My Document.docx", str);
|
|
||||||
});
|
|
@ -1,78 +0,0 @@
|
|||||||
// 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 { Document, Packer } from "../build";
|
|
||||||
|
|
||||||
const doc = new 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({ left: 720 })
|
|
||||||
.spacing({ line: 276 });
|
|
||||||
|
|
||||||
doc.Styles.createParagraphStyle("wellSpaced", "Well Spaced")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.spacing({ line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.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 packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// 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 } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = doc.createTable(4, 4);
|
|
||||||
table
|
|
||||||
.getCell(2, 2)
|
|
||||||
.addContent(new Paragraph("Hello"))
|
|
||||||
.CellProperties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
|
|
||||||
.addBottomBorder(BorderStyle.DOUBLE, 3, "blue")
|
|
||||||
.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green")
|
|
||||||
.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,27 +0,0 @@
|
|||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph1 = new Paragraph().bidirectional();
|
|
||||||
const textRun1 = new TextRun("שלום עולם").rightToLeft();
|
|
||||||
paragraph1.addRun(textRun1);
|
|
||||||
doc.addParagraph(paragraph1);
|
|
||||||
|
|
||||||
const paragraph2 = new Paragraph().bidirectional();
|
|
||||||
const textRun2 = new TextRun("שלום עולם").bold().rightToLeft();
|
|
||||||
paragraph2.addRun(textRun2);
|
|
||||||
doc.addParagraph(paragraph2);
|
|
||||||
|
|
||||||
const paragraph3 = new Paragraph().bidirectional();
|
|
||||||
const textRun3 = new TextRun("שלום עולם").italic().rightToLeft();
|
|
||||||
paragraph3.addRun(textRun3);
|
|
||||||
doc.addParagraph(paragraph3);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,18 +0,0 @@
|
|||||||
// 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 } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = doc.createTable(4, 4);
|
|
||||||
table.getCell(2, 2).addContent(new Paragraph("Hello"));
|
|
||||||
|
|
||||||
const image = Media.addImage(doc, "./demo/images/image1.jpeg");
|
|
||||||
table.getCell(1, 1).addContent(image.Paragraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,22 +0,0 @@
|
|||||||
// 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();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("No border!");
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
const borderParagraph = new Paragraph("I have borders on my top and bottom sides!").createBorder();
|
|
||||||
borderParagraph.Borders.addTopBorder();
|
|
||||||
borderParagraph.Borders.addBottomBorder();
|
|
||||||
|
|
||||||
doc.addParagraph(borderParagraph);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,34 +0,0 @@
|
|||||||
import * as fs from "fs";
|
|
||||||
import { Document, Packer } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
const myStyles = doc.Styles;
|
|
||||||
|
|
||||||
// The first argument is an ID you use to apply the style to paragraphs
|
|
||||||
// The second argument is a human-friendly name to show in the UI
|
|
||||||
myStyles.createParagraphStyle("myWonkyStyle", "My Wonky Style")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.color("990000")
|
|
||||||
.italics()
|
|
||||||
.indent({left: 720}) // 720 TWIP === 720 / 20 pt === .5 in
|
|
||||||
.spacing({line: 276}); // 276 / 240 = 1.15x line spacing
|
|
||||||
|
|
||||||
myStyles.createParagraphStyle("Heading2", "Heading 2")
|
|
||||||
.basedOn("Normal")
|
|
||||||
.next("Normal")
|
|
||||||
.quickFormat()
|
|
||||||
.size(26) // 26 half-points === 13pt font
|
|
||||||
.bold()
|
|
||||||
.underline("double", "FF0000")
|
|
||||||
.spacing({before: 240, after: 120}); // TWIP for both
|
|
||||||
|
|
||||||
doc.createParagraph("Hello").style("myWonkyStyle");
|
|
||||||
doc.createParagraph("World").heading2(); // Uses the Heading2 style
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
console.log("Document created successfully at project root!");
|
|
||||||
});
|
|
@ -1,43 +0,0 @@
|
|||||||
// 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 { File, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
|
|
||||||
|
|
||||||
const doc = new File();
|
|
||||||
|
|
||||||
// The first argument is an ID you use to apply the style to paragraphs
|
|
||||||
// The second argument is a human-friendly name to show in the UI
|
|
||||||
doc.Styles.createParagraphStyle("MySpectacularStyle", "My Spectacular Style")
|
|
||||||
.basedOn("Heading1")
|
|
||||||
.next("Heading1")
|
|
||||||
.color("990000")
|
|
||||||
.italics();
|
|
||||||
|
|
||||||
// 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
|
|
||||||
const toc = new TableOfContents("Summary", {
|
|
||||||
hyperlink: true,
|
|
||||||
headingStyleRange: "1-5",
|
|
||||||
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)],
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.addTableOfContents(toc);
|
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("Header #1").heading1().pageBreakBefore());
|
|
||||||
doc.addParagraph(new Paragraph("I'm a little text very nicely written.'"));
|
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("Header #2").heading1().pageBreakBefore());
|
|
||||||
doc.addParagraph(new Paragraph("I'm a other text very nicely written.'"));
|
|
||||||
doc.addParagraph(new Paragraph("Header #2.1").heading2());
|
|
||||||
doc.addParagraph(new Paragraph("I'm a another text very nicely written.'"));
|
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("My Spectacular Style #1").style("MySpectacularStyle").pageBreakBefore());
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,32 +0,0 @@
|
|||||||
import * as fs from "fs";
|
|
||||||
import { Document, Indent, Numbering, Packer, Paragraph } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const numbering = new Numbering();
|
|
||||||
|
|
||||||
const abstractNum = numbering.createAbstractNumbering();
|
|
||||||
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent({ left: 720, hanging: 260 }));
|
|
||||||
|
|
||||||
const concrete = numbering.createConcreteNumbering(abstractNum);
|
|
||||||
|
|
||||||
const item1 = new Paragraph("line with contextual spacing");
|
|
||||||
const item2 = new Paragraph("line with contextual spacing");
|
|
||||||
const item3 = new Paragraph("line without contextual spacing");
|
|
||||||
const item4 = new Paragraph("line without contextual spacing");
|
|
||||||
|
|
||||||
item1.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
|
||||||
item2.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
|
||||||
item3.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
|
||||||
item4.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
|
||||||
|
|
||||||
doc.addParagraph(item1);
|
|
||||||
doc.addParagraph(item2);
|
|
||||||
doc.addParagraph(item3);
|
|
||||||
doc.addParagraph(item4);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,46 +0,0 @@
|
|||||||
// Numbering and bullet points example
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, Indent, Numbering, Packer, Paragraph } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const numbering = new Numbering();
|
|
||||||
|
|
||||||
const abstractNum = numbering.createAbstractNumbering();
|
|
||||||
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent({ left: 720, hanging: 260 }));
|
|
||||||
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent({ left: 1440, hanging: 980 }));
|
|
||||||
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent({ left: 14402160, hanging: 1700 }));
|
|
||||||
|
|
||||||
const concrete = numbering.createConcreteNumbering(abstractNum);
|
|
||||||
|
|
||||||
const topLevelP = new Paragraph("Hey you");
|
|
||||||
const subP = new Paragraph("What's up fam");
|
|
||||||
const secondSubP = new Paragraph("Hello World 2");
|
|
||||||
const subSubP = new 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);
|
|
||||||
|
|
||||||
const bullet1 = new Paragraph("Hey you").bullet();
|
|
||||||
const bullet2 = new Paragraph("What's up fam").bullet(1);
|
|
||||||
const bullet3 = new Paragraph("Hello World 2").bullet(2);
|
|
||||||
const bullet4 = new Paragraph("Yeah boi").bullet(3);
|
|
||||||
|
|
||||||
doc.addParagraph(bullet1);
|
|
||||||
doc.addParagraph(bullet2);
|
|
||||||
doc.addParagraph(bullet3);
|
|
||||||
doc.addParagraph(bullet4);
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
// 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 } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = doc.createTable(4, 4);
|
|
||||||
table.getCell(2, 2).addContent(new Paragraph("Hello"));
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// 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";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/dog.png").toString("base64"));
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/cat.jpg"));
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/parrots.bmp"));
|
|
||||||
doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,29 +0,0 @@
|
|||||||
// 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, Packer, Paragraph, TextRun } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document(undefined, {
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const paragraph = new Paragraph("Hello World");
|
|
||||||
const institutionText = new TextRun("Foo bar").bold();
|
|
||||||
const dateText = new TextRun("Github is the best").tab().bold();
|
|
||||||
paragraph.addRun(institutionText);
|
|
||||||
paragraph.addRun(dateText);
|
|
||||||
|
|
||||||
doc.addParagraph(paragraph);
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World").heading1();
|
|
||||||
doc.createParagraph("Foo bar");
|
|
||||||
doc.createParagraph("Github is the best");
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,17 +0,0 @@
|
|||||||
// Add text to header and footer
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, Packer } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World");
|
|
||||||
|
|
||||||
doc.Header.createParagraph("Header text");
|
|
||||||
doc.Footer.createParagraph("Footer text");
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
@ -1,17 +0,0 @@
|
|||||||
// Add images to header and footer
|
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
|
||||||
import * as fs from "fs";
|
|
||||||
import { Document, Packer } from "../build";
|
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
doc.createParagraph("Hello World");
|
|
||||||
|
|
||||||
doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
doc.Footer.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
const packer = new Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
BIN
demo/dotx/template.dotx
Normal file
BIN
demo/dotx/template.dotx
Normal file
Binary file not shown.
@ -19,13 +19,16 @@ prompt.start();
|
|||||||
|
|
||||||
prompt.get(schema, (_, result) => {
|
prompt.get(schema, (_, result) => {
|
||||||
const demoNumber = result.number;
|
const demoNumber = result.number;
|
||||||
const filePath = `./demo/demo${demoNumber}.ts`;
|
const files = fs.readdirSync("./demo").filter((fn) => fn.startsWith(demoNumber));
|
||||||
|
|
||||||
if (!fs.existsSync(filePath)) {
|
if (files.length === 0) {
|
||||||
console.error(`demo${demoNumber} does not exist: ${filePath}`);
|
console.error(`demo number ${demoNumber} does not exist`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Running demo ${demoNumber}`);
|
|
||||||
|
const filePath = `./demo/${files[0]}`;
|
||||||
|
|
||||||
|
console.log(`Running demo ${demoNumber}: ${files[0]}`);
|
||||||
if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) {
|
if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) {
|
||||||
console.log("Document created successfully");
|
console.log("Document created successfully");
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="clippy the assistant" src="https://i.imgur.com/pwCV6L8.png">
|
<img alt="clippy the assistant" src="https://i.imgur.com/37uBGhO.gif">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -18,34 +18,52 @@ npm install --save docx
|
|||||||
|
|
||||||
Then you can `require` or `import` as usual:
|
Then you can `require` or `import` as usual:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
let docx = require("docx");
|
const docx = require("docx");
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
import * as docx from "docx";
|
import * as docx from "docx";
|
||||||
|
// or
|
||||||
|
import { ... } from "docx";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var docx = require("docx");
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||||
|
|
||||||
// Create document
|
// Create document
|
||||||
var doc = new docx.Document();
|
const doc = new Document();
|
||||||
|
|
||||||
// Add some content in the document
|
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
||||||
var paragraph = new docx.Paragraph("Some cool text here.");
|
// This simple example will only contain one section
|
||||||
// Add more text into the paragraph if you wish
|
doc.addSection({
|
||||||
paragraph.addRun(new docx.TextRun("Lorem Ipsum Foo Bar"));
|
properties: {},
|
||||||
doc.addParagraph(paragraph);
|
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
|
// Used to export the file into a .docx file
|
||||||
var exporter = new docx.LocalPacker(doc);
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
||||||
|
|
||||||
exporter.pack("My First Document");
|
// Done! A file called 'My First Document.docx' will be in your file system.
|
||||||
|
|
||||||
// Done! A file called 'My First Document.docx' will be in your file system if you used LocalPacker
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Honoured Mentions
|
## Honoured Mentions
|
||||||
|
@ -9,14 +9,17 @@
|
|||||||
* Usage
|
* Usage
|
||||||
|
|
||||||
* [Document](usage/document.md)
|
* [Document](usage/document.md)
|
||||||
|
* [Sections](usage/sections.md)
|
||||||
* [Paragraph](usage/paragraph.md)
|
* [Paragraph](usage/paragraph.md)
|
||||||
* [Text](usage/text.md)
|
* [Text](usage/text.md)
|
||||||
* [Image](usage/images.md)
|
* [Image](usage/images.md)
|
||||||
* [Headers & Footers](usage/headers-and-footers.md)
|
* [Headers & Footers](usage/headers-and-footers.md)
|
||||||
* [Bullet Points](usage/bullet-points.md)
|
* [Bullet Points](usage/bullet-points.md)
|
||||||
* [Numbering](usage/numbering.md)
|
* [Numbering](usage/numbering.md)
|
||||||
|
* [Tables](usage/tables.md)
|
||||||
* [Tab Stops](usage/tab-stops.md)
|
* [Tab Stops](usage/tab-stops.md)
|
||||||
* [Table of Contents](usage/table-of-contents.md)
|
* [Table of Contents](usage/table-of-contents.md)
|
||||||
|
* [Page Numbers](usage/page-numbers.md)
|
||||||
* Styling
|
* Styling
|
||||||
* [Styling with JS](usage/styling-with-js.md)
|
* [Styling with JS](usage/styling-with-js.md)
|
||||||
* [Styling with XML](usage/styling-with-xml.md)
|
* [Styling with XML](usage/styling-with-xml.md)
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
# Contribution Guidelines
|
# Contribution Guidelines
|
||||||
|
|
||||||
## Writing Code
|
|
||||||
|
|
||||||
* Include documentation reference(s) at the top of each file:
|
* Include documentation reference(s) at the top of each file:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
// http://officeopenxml.com/WPdocument.php
|
// http://officeopenxml.com/WPdocument.php
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -12,23 +10,89 @@
|
|||||||
|
|
||||||
* Follow the `TSLint` rules
|
* Follow the `TSLint` rules
|
||||||
|
|
||||||
|
## Always think about the user
|
||||||
|
|
||||||
|
The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
|
||||||
|
|
||||||
|
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 consistent with the rest of the API?
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
## No leaky components in API interface
|
||||||
|
|
||||||
|
> This mainly applies to the API the end user will consume.
|
||||||
|
|
||||||
|
Try to make method parameters of the outside API accept primitives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
|
||||||
|
|
||||||
|
This is so that:
|
||||||
|
|
||||||
|
1. Imports are much cleaner for the end user, no need for:
|
||||||
|
```ts
|
||||||
|
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
|
||||||
|
```
|
||||||
|
|
||||||
|
2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
|
||||||
|
3. It means the end user does not need to import and create the child component to be injected.
|
||||||
|
|
||||||
|
**Do not**
|
||||||
|
|
||||||
|
`TableFloatProperties` is a class. The outside world would have to `new` up the object, and inject it in like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
public float(tableFloatProperties: TableFloatProperties): Table
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table.float(new TableFloatProperties(...));
|
||||||
|
```
|
||||||
|
|
||||||
|
**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
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table.float({...});
|
||||||
|
```
|
||||||
|
|
||||||
## Add vs Create
|
## Add vs Create
|
||||||
|
|
||||||
This is just a guideline, and the rules can sometimes be broken.
|
This is just a guideline, and the rules can sometimes be broken.
|
||||||
|
|
||||||
* Use `create` if the method `new`'s up an element inside:
|
* Use `create` if the method `new`'s up an element inside:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
public createParagraph() {
|
public createParagraph() {
|
||||||
const paragraph = new Paragraph();
|
const paragraph = new Paragraph();
|
||||||
this.root.push(paragraph);
|
this.root.push(paragraph);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* Use `add` if you add the element into the method as a parameter:
|
* Use `add` if you add the element into the method as a parameter.
|
||||||
|
*Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
public addParagraph(paragraph: Paragraph) {
|
public add(paragraph: Paragraph) {
|
||||||
this.root.push(paragraph);
|
this.root.push(paragraph);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -37,9 +101,9 @@ This is just a guideline, and the rules can sometimes be broken.
|
|||||||
|
|
||||||
Getters and Setters are done with a capital letter like so:
|
Getters and Setters are done with a capital letter like so:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
public get Level() {
|
public get Level() {
|
||||||
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -47,23 +111,127 @@ There is no performance advantage by doing this. It means we don't need to prefi
|
|||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
private get _level: string;
|
private get _level: string;
|
||||||
```
|
```
|
||||||
|
|
||||||
**Do**
|
**Do**
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
private get level: string;
|
private get level: string;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Temporal Methods
|
||||||
|
|
||||||
|
Some methods are `non-temporal`, which means regardless of when you call the method, it will have the same affect on the document. For example, setting the width of a table at the end of the document will have the same effect as setting the width at the start:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
table.setWidth(1000); // now removed as of version 5.0.0
|
||||||
|
```
|
||||||
|
|
||||||
|
Whereas some methods are `temporal`, which means depending on the time-frame they are called, it would produce a difference result. For example, moving `createParagraph()` around your code will physically alter the document.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.createParagraph("hello");
|
||||||
|
```
|
||||||
|
|
||||||
|
If a method is `non-temporal`, put it in the objects `constructor`. For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table(width: number);
|
||||||
|
```
|
||||||
|
|
||||||
|
`Non-temporal` methods are usually methods which can only be used one time and one time only. For example, `.float()`. It does not make sense to call `.float()` again if its already floating.
|
||||||
|
|
||||||
|
I am not sure what the real term is, but this will do.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
I am not sure where these habits in software development come from, but I do not believe it is beneficial:
|
||||||
|
|
||||||
|
**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
|
## Testing
|
||||||
|
|
||||||
Please write a test of every file you make and suffix it with `.spec.ts`.
|
Please write a test of every file you make and suffix it with `.spec.ts`.
|
||||||
|
|
||||||
Here is a template of a test:
|
Here is a template of a test:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
|
||||||
describe("ClassName", () => {
|
describe("ClassName", () => {
|
||||||
@ -78,3 +246,5 @@ describe("ClassName", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Try not to use the `tests/utility.ts` file as this is being deprecated.
|
||||||
|
@ -14,7 +14,7 @@ This command will run the `demo selector app` in the `/demo` folder. It will pro
|
|||||||
|
|
||||||
A simple hello world of the `docx` library:
|
A simple hello world of the `docx` library:
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
|
|||||||
|
|
||||||
This example shows how to customise the look and feel of a document using JS configuration
|
This example shows how to customise the look and feel of a document using JS configuration
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
|
|||||||
|
|
||||||
This example shows how to customise the look and feel of a document using XML configuration
|
This example shows how to customise the look and feel of a document using XML configuration
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
|
|||||||
|
|
||||||
This example shows many levels of numbering
|
This example shows many levels of numbering
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
|
|||||||
|
|
||||||
Example of simple table
|
Example of simple table
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
|
|||||||
|
|
||||||
Styling the borders of a table
|
Styling the borders of a table
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
|
|||||||
|
|
||||||
Importing Images from file system path
|
Importing Images from file system path
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
|
|||||||
|
|
||||||
Example showing how to add image to headers and footers
|
Example showing how to add image to headers and footers
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
|
|||||||
|
|
||||||
Example showing how to scale images
|
Example showing how to scale images
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
|
|||||||
|
|
||||||
This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image
|
This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
|
|||||||
|
|
||||||
As before, to add an image to a table, you would need to add it to the `Media` object first
|
As before, to add an image to a table, you would need to add it to the `Media` object first
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
|
||||||
|
|
||||||
@ -106,15 +106,15 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
|
|||||||
|
|
||||||
If you want to use a Base64 image instead
|
If you want to use a Base64 image instead
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
|
||||||
|
|
||||||
## Margins
|
## Margins
|
||||||
|
|
||||||
Example showing how to set custom margains
|
Example showing how to set custom margins
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
|
|||||||
|
|
||||||
Example showing how to set the document to `landscape` or `portrait`
|
Example showing how to set the document to `landscape` or `portrait`
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
|
|||||||
|
|
||||||
Example showing how to add headers and footers
|
Example showing how to add headers and footers
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ Check out `Sections` for this feature
|
|||||||
|
|
||||||
Example showing how to page break
|
Example showing how to page break
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
|
||||||
|
|
||||||
@ -152,15 +152,16 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
|
|||||||
|
|
||||||
Example showing how to page break before like in Word
|
Example showing how to page break before like in Word
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_
|
||||||
|
|
||||||
## Sections
|
## Sections
|
||||||
|
|
||||||
Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document
|
Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document.
|
||||||
|
Also you can have different page number formats and starts for different sections.
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
|
||||||
|
|
||||||
@ -168,7 +169,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
|
|||||||
|
|
||||||
Example of how to add footnotes. Good for references
|
Example of how to add footnotes. Good for references
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
|
|||||||
|
|
||||||
Example showing how to use the Buffer packer and then write that buffer to the file system
|
Example showing how to use the Buffer packer and then write that buffer to the file system
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
|
|||||||
|
|
||||||
Example showing how to make bookmarks to make internal hyperlinks within the document
|
Example showing how to make bookmarks to make internal hyperlinks within the document
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
|
|||||||
|
|
||||||
Example showing how to use bidirectional text for certain languages such as Hebrew
|
Example showing how to use bidirectional text for certain languages such as Hebrew
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
|
|||||||
|
|
||||||
Example showing how to add headers and footers
|
Example showing how to add headers and footers
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
|
||||||
|
|
||||||
@ -213,6 +214,6 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
|
|||||||
|
|
||||||
This example shows how to customise the look and feel of a document and add images
|
This example shows how to customise the look and feel of a document and add images
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ":include")
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ':include')
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<script src="//unpkg.com/docsify/lib/plugins/emoji.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="https://unpkg.com/docsify-copy-code@2"></script>
|
||||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||||
|
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -4,18 +4,17 @@
|
|||||||
|
|
||||||
To make a bullet point, simply make a paragraph into a bullet point:
|
To make a bullet point, simply make a paragraph into a bullet point:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var text = new docx.TextRun("Bullet points");
|
const text = new TextRun("Bullet points");
|
||||||
var paragraph = new docx.Paragraph(text).bullet();
|
const paragraph = new Paragraph({
|
||||||
|
text: "Bullet points",
|
||||||
var text2 = new docx.TextRun("Are awesome");
|
bullet: {
|
||||||
var paragraph2 = new docx.Paragraph(text2).bullet();
|
level: 0, // How deep you want the bullet to me
|
||||||
|
},
|
||||||
doc.addParagraph(paragraph);
|
});
|
||||||
doc.addParagraph(paragraph2);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### This will produce:
|
### This will produce:
|
||||||
|
|
||||||
* Bullet points
|
- Bullet points
|
||||||
* Are awesome
|
- Are awesome
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
|
|
||||||
To create a new document, it is very easy:
|
To create a new document, it is very easy:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Document properties
|
## Document properties
|
||||||
|
|
||||||
You can add properties to the Word document by specifying options, for example:
|
You can add properties to the Word document by specifying options, for example:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var doc = new docx.Document({
|
const doc = new docx.Document({
|
||||||
creator: "Dolan Miu",
|
creator: "Dolan Miu",
|
||||||
description: "My extremely interesting document",
|
description: "My extremely interesting document",
|
||||||
title: "My Document",
|
title: "My Document",
|
||||||
@ -22,14 +22,18 @@ var doc = new docx.Document({
|
|||||||
|
|
||||||
### Full list of options:
|
### Full list of options:
|
||||||
|
|
||||||
```
|
|
||||||
creator
|
* creator
|
||||||
description
|
* description
|
||||||
title
|
* title
|
||||||
subject
|
* subject
|
||||||
keywords
|
* keywords
|
||||||
lastModifiedBy
|
* lastModifiedBy
|
||||||
revision
|
* revision
|
||||||
```
|
|
||||||
|
|
||||||
You can mix and match whatever properties you want, or provide no properties.
|
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.
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
# Headers and Footers
|
# Headers and Footers
|
||||||
|
|
||||||
## Example
|
!> Headers and Footers requires an understanding of [Sections](usage/sections.md).
|
||||||
|
|
||||||
Creating Headers and footers is simple. Access the `Header` and `Footer` by doing so like this:
|
Every Section has a sections which you can define its Headers and Footers:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
doc.Header;
|
|
||||||
doc.Footer;
|
|
||||||
```
|
|
||||||
|
|
||||||
You can call the same methods as you would with a `File`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
doc.Header.createParagraph("Header text");
|
|
||||||
doc.Footer.createParagraph("Footer text");
|
|
||||||
```
|
|
||||||
|
|
||||||
Even add images:
|
|
||||||
|
|
||||||
```js
|
|
||||||
doc.Header.createImage([BUFFER_OF_YOUR_IMAGE]);
|
|
||||||
doc.Footer.createImage([BUFFER_OF_YOUR_IMAGE]);
|
|
||||||
```
|
|
||||||
|
|
||||||
Refer to `demo8.js` for more information
|
|
||||||
|
|
||||||
## Multiple Headers and Footers
|
|
||||||
|
|
||||||
Also all the supported section properties are implemented according to: http://officeopenxml.com/WPsection.php
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
const header = this.document.createHeader();
|
|
||||||
const footer = this.document.createFooter();
|
|
||||||
|
|
||||||
// Add new section with another header and footer
|
|
||||||
doc.addSection({
|
doc.addSection({
|
||||||
headerId: header.Header.ReferenceId,
|
headers: {
|
||||||
footerId: footer.Footer.ReferenceId,
|
default: new Header({ // The standard default header
|
||||||
pageNumberStart: 1,
|
children: [],
|
||||||
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
}),
|
||||||
|
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()
|
||||||
|
```
|
@ -1,156 +1,248 @@
|
|||||||
# Images
|
# Images
|
||||||
|
|
||||||
## Intro
|
!> Images requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
Adding images is very simple
|
To create a `floating` image on top of text:
|
||||||
|
|
||||||
Simply call the `createImage` method:
|
```ts
|
||||||
|
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
||||||
```js
|
|
||||||
const image = doc.createImage([BUFFER_OF_YOUR_IMAGE]);
|
|
||||||
```
|
|
||||||
|
|
||||||
`docx` supports `jpeg`, `jpg`, `bmp`, `gif` and `png`
|
|
||||||
|
|
||||||
Check `demo5.js` for an example
|
|
||||||
|
|
||||||
## Positioning
|
|
||||||
|
|
||||||
Images can be:
|
|
||||||
|
|
||||||
* floating position of images
|
|
||||||
* Wrapped around the text
|
|
||||||
* Inline
|
|
||||||
|
|
||||||
By default, picture are exported as `INLINE` elements.
|
|
||||||
|
|
||||||
In Word this is found in:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
The `PictureRun` element support various options to define the positioning of the element in the document.
|
|
||||||
|
|
||||||
```js
|
|
||||||
interface DrawingOptions {
|
|
||||||
position?: PlacementPosition;
|
|
||||||
textWrapping?: TextWrapping;
|
|
||||||
floating?: Floating;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
can be passed when creating `PictureRun()` for example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const imageData = document.createImage(buffer, 903, 1149);
|
|
||||||
|
|
||||||
new docx.PictureRun(imageData, {
|
|
||||||
position: docx.PlacementPosition.FLOATING,
|
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
relative: HorizontalPositionRelativeFrom.PAGE,
|
offset: 1014400,
|
||||||
align: HorizontalPositionAlign.LEFT,
|
|
||||||
},
|
},
|
||||||
verticalPosition: {
|
verticalPosition: {
|
||||||
relative: VerticalPositionRelativeFrom.PAGE,
|
offset: 1014400,
|
||||||
align: VerticalPositionAlign.TOP,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
So, the first thing is to define the placement position: `INLINE` or `FLOATING`. Inline is the default one so there is no need to pass drawing options for inline.
|
By default with no arguments, its an `inline` image:
|
||||||
|
|
||||||
When placement position is FLOATING then we can use two options:
|
```ts
|
||||||
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
||||||
### Wrap text
|
|
||||||
|
|
||||||
for `drawingOptions.textWrapping` we can define various options. `textWrapping` has the following properties:
|
|
||||||
|
|
||||||
```js
|
|
||||||
interface TextWrapping {
|
|
||||||
textWrapStyle: TextWrapStyle;
|
|
||||||
wrapTextOption?: WrapTextOption;
|
|
||||||
distanceFromText?: Distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum TextWrapStyle {
|
|
||||||
NONE,
|
|
||||||
SQUARE,
|
|
||||||
TIGHT,
|
|
||||||
TOP_AND_BOTTOM,
|
|
||||||
}
|
|
||||||
|
|
||||||
enum WrapTextOption {
|
|
||||||
BOTH_SIDES = "bothSides",
|
|
||||||
LEFT = "left",
|
|
||||||
RIGHT = "right",
|
|
||||||
LARGEST = "largest",
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Floating position
|
Add it into the document by adding the image into a paragraph:
|
||||||
|
|
||||||
When we want to position the image relative or absolute then we need to use option `drawingOptions.floating`:
|
```ts
|
||||||
|
doc.addSection({
|
||||||
```js
|
children: [new Paragraph(image)],
|
||||||
export interface Floating {
|
});
|
||||||
horizontalPosition: HorizontalPositionOptions;
|
|
||||||
verticalPosition: VerticalPositionOptions;
|
|
||||||
allowOverlap?: boolean;
|
|
||||||
lockAnchor?: boolean;
|
|
||||||
behindDocument?: boolean;
|
|
||||||
layoutInCell?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface HorizontalPositionOptions {
|
|
||||||
relative: HorizontalPositionRelativeFrom;
|
|
||||||
align?: HorizontalPositionAlign;
|
|
||||||
offset?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VerticalPositionOptions {
|
|
||||||
relative: VerticalPositionRelativeFrom;
|
|
||||||
align?: VerticalPositionAlign;
|
|
||||||
offset?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum HorizontalPositionRelativeFrom {
|
|
||||||
CHARACTER = "character",
|
|
||||||
COLUMN = "column",
|
|
||||||
INSIDE_MARGIN = "insideMargin",
|
|
||||||
LEFT_MARGIN = "leftMargin",
|
|
||||||
MARGIN = "margin",
|
|
||||||
OUTSIDE_MARGIN = "outsideMargin",
|
|
||||||
PAGE = "page",
|
|
||||||
RIGHT_MARGIN = "rightMargin",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum VerticalPositionRelativeFrom {
|
|
||||||
BOTTOM_MARGIN = "bottomMargin",
|
|
||||||
INSIDE_MARGIN = "insideMargin",
|
|
||||||
LINE = "line",
|
|
||||||
MARGIN = "margin",
|
|
||||||
OUTSIDE_MARGIN = "outsideMargin",
|
|
||||||
PAGE = "page",
|
|
||||||
PARAGRAPH = "paragraph",
|
|
||||||
TOP_MARGIN = "topMargin",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum HorizontalPositionAlign {
|
|
||||||
CENTER = "center",
|
|
||||||
INSIDE = "inside",
|
|
||||||
LEFT = "left",
|
|
||||||
OUTSIDE = "outside",
|
|
||||||
RIGHT = "right",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum VerticalPositionAlign {
|
|
||||||
BOTTOM = "bottom",
|
|
||||||
CENTER = "center",
|
|
||||||
INSIDE = "inside",
|
|
||||||
OUTSIDE = "outside",
|
|
||||||
TOP = "top",
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
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 |
|
||||||
|
|
||||||
|
`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_
|
||||||
|
@ -26,7 +26,7 @@ _levels_ which form a sequence starting at 0 indicating the top-level
|
|||||||
list look and increasing from there to descibe the sublists, then
|
list look and increasing from there to descibe the sublists, then
|
||||||
sub-sublists, etc. Each level includes the following properties:
|
sub-sublists, etc. Each level includes the following properties:
|
||||||
|
|
||||||
* **level**: This its 0-based index in the defintion stack
|
* **level**: This is its 0-based index in the definition stack
|
||||||
* **numberFormat**: This indicates how the bullet or number should be
|
* **numberFormat**: This indicates how the bullet or number should be
|
||||||
generated. Options include `bullet` (meaning don't count), `decimal`
|
generated. Options include `bullet` (meaning don't count), `decimal`
|
||||||
(arabic numerals), `upperRoman`, `lowerRoman`, `hex`, and many
|
(arabic numerals), `upperRoman`, `lowerRoman`, `hex`, and many
|
||||||
@ -64,10 +64,10 @@ styles or numbering of any kind, you'll have to use the
|
|||||||
`docx.Numbering` class.
|
`docx.Numbering` class.
|
||||||
|
|
||||||
First you need to create a new numbering container class and use it to
|
First you need to create a new numbering container class and use it to
|
||||||
create your abstract numbering style, define your levels, and creat
|
create your abstract numbering style, define your levels, and create
|
||||||
your concreate numbering style:
|
your concrete numbering style:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const numbering = new docx.Numbering();
|
const numbering = new docx.Numbering();
|
||||||
|
|
||||||
const abstractNum = numbering.createAbstractNumbering();
|
const abstractNum = numbering.createAbstractNumbering();
|
||||||
@ -75,22 +75,14 @@ abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new
|
|||||||
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent(1440, 980));
|
abstractNum.createLevel(1, "decimal", "%2.", "start").addParagraphProperty(new Indent(1440, 980));
|
||||||
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent(2160, 1700));
|
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").addParagraphProperty(new Indent(2160, 1700));
|
||||||
|
|
||||||
const concrete = numbering.createConcreteNumbering(numberedAbstract);
|
const concrete = numbering.createConcreteNumbering(abstractNum);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then apply your concrete style to paragraphs using their
|
You can then apply your concrete style to paragraphs using the
|
||||||
`#setNumbering` method:
|
`setNumbering` method:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
topLevelP.setNumbering(concrete, 0);
|
topLevelP.setNumbering(concrete, 0);
|
||||||
subP.setNumbering(concrete, 1);
|
subP.setNumbering(concrete, 1);
|
||||||
subSubP.setNumbering(concrete, 2);
|
subSubP.setNumbering(concrete, 2);
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, you need to let your exporter know about your numbering
|
|
||||||
styles when you're ready to render the document:
|
|
||||||
|
|
||||||
```js
|
|
||||||
const packer = new Packer(doc, undefined, undefined, numbering);
|
|
||||||
packer.pack(myOutput);
|
|
||||||
```
|
|
||||||
|
@ -2,15 +2,50 @@
|
|||||||
|
|
||||||
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
|
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
|
||||||
|
|
||||||
## Version 4
|
|
||||||
|
|
||||||
Packers in `version 4` and above are now one single `Packer`. It 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.
|
Packers in `version 4` and above are now one single `Packer`. It 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.
|
||||||
|
|
||||||
|
## Version 5
|
||||||
|
|
||||||
|
Packers in `version 5` and above are now static methods on `Packer`.
|
||||||
|
|
||||||
### Export as Buffer
|
### Export as Buffer
|
||||||
|
|
||||||
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
|
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
|
||||||
|
|
||||||
```js
|
```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");
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version 4
|
||||||
|
|
||||||
|
The `Packer` in `version 4` requires an instance of `Packer`, so be sure to `new` it.
|
||||||
|
|
||||||
|
### Export as Buffer
|
||||||
|
|
||||||
|
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
|
||||||
|
|
||||||
|
```ts
|
||||||
const packer = new docx.Packer();
|
const packer = new docx.Packer();
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
@ -20,7 +55,7 @@ packer.toBuffer(doc).then((buffer) => {
|
|||||||
|
|
||||||
### Export as a `base64` string
|
### Export as a `base64` string
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const packer = new docx.Packer();
|
const packer = new docx.Packer();
|
||||||
|
|
||||||
packer.toBase64String(doc).then((string) => {
|
packer.toBase64String(doc).then((string) => {
|
||||||
@ -32,7 +67,7 @@ packer.toBase64String(doc).then((string) => {
|
|||||||
|
|
||||||
This is useful if you want to send it as an downloadable in a browser environment.
|
This is useful if you want to send it as an downloadable in a browser environment.
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const packer = new docx.Packer();
|
const packer = new docx.Packer();
|
||||||
|
|
||||||
packer.toBlob(doc).then((blob) => {
|
packer.toBlob(doc).then((blob) => {
|
||||||
@ -45,7 +80,7 @@ packer.toBlob(doc).then((blob) => {
|
|||||||
|
|
||||||
### File System Packer
|
### File System Packer
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const docx = require("docx");
|
const docx = require("docx");
|
||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
@ -56,7 +91,7 @@ exporter.pack("My Document");
|
|||||||
|
|
||||||
### Buffer Packer
|
### Buffer Packer
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const docx = require("docx");
|
const docx = require("docx");
|
||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
@ -68,7 +103,7 @@ const buffer = exporter.pack();
|
|||||||
|
|
||||||
Creates a `node` `Readable` stream
|
Creates a `node` `Readable` stream
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const docx = require("docx");
|
const docx = require("docx");
|
||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
@ -88,7 +123,7 @@ I used the express exporter in my [website](http://www.dolan.bio).
|
|||||||
|
|
||||||
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
|
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const docx = require("docx");
|
const docx = require("docx");
|
||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
@ -107,7 +142,7 @@ where `res` is the response object obtained through the Express router. It is th
|
|||||||
|
|
||||||
You can export your word document as a PDF file like so:
|
You can export your word document as a PDF file like so:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const exporter = new docx.LocalPacker(doc);
|
const exporter = new docx.LocalPacker(doc);
|
||||||
exporter.packPdf("My Document");
|
exporter.packPdf("My Document");
|
||||||
|
|
||||||
|
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_
|
@ -2,28 +2,180 @@
|
|||||||
|
|
||||||
> Everything (text, images, graphs etc) in OpenXML is organised in paragraphs.
|
> Everything (text, images, graphs etc) in OpenXML is organised in paragraphs.
|
||||||
|
|
||||||
## Example
|
!> Paragraphs requires an understanding of [Sections](sections.md).
|
||||||
|
|
||||||
You can add more text to the paragraph by doing this:
|
You can create `Paragraphs` in the following ways:
|
||||||
|
|
||||||
```js
|
### Shorthand
|
||||||
var paragraph = new docx.Paragraph(),
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph("Short hand Hello World");
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
### Children Method
|
||||||
var text = new docx.TextRun("Lorem Ipsum Foo Bar");
|
|
||||||
var paragraph = new docx.Paragraph();
|
This method is useful for adding different [text](text.md) with different styles, [symbols](symbols.md), or adding [images](images.md) inline.
|
||||||
paragraph.addRun(text);
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World"), new SymbolRun("F071")],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
### Explicit
|
||||||
var paragraph = new docx.Paragraph("Short hand notation for adding text.");
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Short hand notation for adding text.",
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
After you create the paragraph, you must add the paragraph into the `document`:
|
After you create the paragraph, you must add the paragraph into the `document's section`. Learn more about `sections` here:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
doc.addParagraph(paragraph);
|
doc.addSection({
|
||||||
|
children: [paragraph],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
This is the list of options for a paragraph. A detailed explanation is below:
|
||||||
|
|
||||||
|
| Property | Type | Mandatory? | Possible Values |
|
||||||
|
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------- |
|
||||||
|
| [text](#text) | `string` | Optional | |
|
||||||
|
| [heading](#heading) | `HeadingLevel` | Optional | `HEADING_1`, `HEADING_2`, `HEADING_3`, `HEADING_4`, `HEADING_5`, `HEADING_6`, `TITLE` |
|
||||||
|
| [border](#border) | `IBorderOptions` | Optional | `top`, `bottom`, `left`, `right`. Each of these are of type IBorderPropertyOptions. Click here for Example |
|
||||||
|
| [spacing](#spacing) | `ISpacingProperties` | Optional | See below for ISpacingProperties |
|
||||||
|
| [outlineLevel](#outline-level) | `number` | Optional | |
|
||||||
|
| alignment | `AlignmentType` | Optional | |
|
||||||
|
| heading | `HeadingLevel` | Optional | |
|
||||||
|
| bidirectional | `boolean` | Optional | |
|
||||||
|
| thematicBreak | `boolean` | Optional | |
|
||||||
|
| pageBreakBefore | `boolean` | Optional | |
|
||||||
|
| contextualSpacing | `boolean` | Optional | |
|
||||||
|
| indent | `IIndentAttributesProperties` | Optional | |
|
||||||
|
| keepLines | `boolean` | Optional | |
|
||||||
|
| keepNext | `boolean` | Optional | |
|
||||||
|
| children | `(TextRun or PictureRun or Hyperlink)[]` | Optional | |
|
||||||
|
| style | `string` | Optional | |
|
||||||
|
| tabStop | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||||
|
| bullet | `{ level: number }` | Optional | |
|
||||||
|
| numbering | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||||
|
|
||||||
|
## Text
|
||||||
|
|
||||||
|
This is the text in a paragraph. You can also add text by using the `Paragraph` shorthand (mentioned above) or adding `children`.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Hello World",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Heading
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
Setting a Heading 1 paragraph with "Hello World" as it's text:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Hello World",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Border
|
||||||
|
|
||||||
|
Add borders to a `Paragraph`. Good for making the `Paragraph` stand out
|
||||||
|
|
||||||
|
#### IBorderPropertyOptions
|
||||||
|
|
||||||
|
`top`, `bottom`, `left`, `right` of the border
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| -------- | -------- | -------- |
|
||||||
|
| color | `string` | Required |
|
||||||
|
| space | `number` | Required |
|
||||||
|
| value | `string` | Required |
|
||||||
|
| size | `number` | Required |
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
Add border on the top and the bottom of the paragraph
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = 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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Spacing
|
||||||
|
|
||||||
|
Adding spacing between paragraphs
|
||||||
|
|
||||||
|
### ISpacingProperties
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| -------- | -------- | -------- |
|
||||||
|
| after | `number` | Optional |
|
||||||
|
| before | `number` | Optional |
|
||||||
|
| line | `number` | Optional |
|
||||||
|
| lineRule | `string` | Optional |
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
Add spacing before the paragraph:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Paragraph with spacing before",
|
||||||
|
spacing: {
|
||||||
|
before: 200,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Outline Level
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
outlineLevel: 0,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Styles
|
## Styles
|
||||||
@ -32,66 +184,72 @@ To create styles, please refer to the styling Wiki: https://github.com/dolanmiu/
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Heading1 - Heading5
|
### Headings and titles
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
paragraph.heading1();
|
import { HeadingLevel, Paragraph } from "docx";
|
||||||
paragraph.heading2();
|
|
||||||
paragraph.heading3();
|
|
||||||
paragraph.heading4();
|
|
||||||
paragraph.heading5();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Title
|
const paragraph = new Paragraph({
|
||||||
|
text: "Hello World",
|
||||||
```js
|
heading: HeadingLevel.TITLE,
|
||||||
paragraph.title();
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Text Alignment
|
## Text Alignment
|
||||||
|
|
||||||
To change the text alignment of a paragraph, for center, left, right or justified:
|
To change the text alignment of a paragraph, add an `AlignmentType` option on the paragraph.for center, left, right or justified:
|
||||||
|
|
||||||
```js
|
**Example:**
|
||||||
paragraph.center();
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
paragraph.left();
|
const paragraph = new Paragraph({
|
||||||
```
|
text: "Hello World",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
```js
|
alignment: AlignmentType.CENTER,
|
||||||
paragraph.right();
|
});
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
paragraph.justified();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Example
|
|
||||||
|
|
||||||
```js
|
|
||||||
paragraph.heading1().center();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The above will create a `heading 1` which is `centered`.
|
The above will create a `heading 1` which is `centered`.
|
||||||
|
|
||||||
|
### Justified text with breaks
|
||||||
|
|
||||||
|
When a paragraph is justified, you may want to not justify the contents of incomplete lines, which end in a soft line break.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
This is possible to achieve using:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
this.doc.Settings.addCompatibility().doNotExpandShiftReturn();
|
||||||
|
```
|
||||||
|
|
||||||
|
The result is:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Thematic Break
|
## Thematic Break
|
||||||
|
|
||||||
To add a break in the page, simply add `.thematicBreak()` on a paragraph:
|
To add a thematic break in the `Paragraph`:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var paragraph = new docx.Paragraph("Amazing Heading").heading1().thematicBreak();
|
const paragraph = new docx.Paragraph("Amazing Heading");
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "Amazing Heading",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
thematicBreak: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
The above example will create a heading with a page break directly under it.
|
The above example will create a heading with a page break directly under it.
|
||||||
|
|
||||||
## Page Break
|
## Page Break
|
||||||
|
|
||||||
To move to a new page (insert a page break), simply add `.pageBreak()` on a paragraph:
|
To move to a new page (insert a page break):
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var paragraph = new docx.Paragraph("Amazing Heading").heading1().pageBreak();
|
const paragraph = new docx.Paragraph({
|
||||||
|
children: [new TextRun("Amazing Heading"), new PageBreak()],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
The above example will create a heading and start a new page immediately afterwards.
|
The above example will create a heading and start a new page immediately afterwards.
|
||||||
@ -100,13 +258,16 @@ The above example will create a heading and start a new page immediately afterwa
|
|||||||
|
|
||||||
This option (available in word) will make sure that the paragraph will start on a new page (if it's not already on a new page).
|
This option (available in word) will make sure that the paragraph will start on a new page (if it's not already on a new page).
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var paragraph = new docx.Paragraph("Hello World on another page").pageBreakBefore();
|
const paragraph = new Paragraph({
|
||||||
|
text: "Hello World on another page",
|
||||||
|
pageBreakBefore: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo15.js
|
Example: https://github.com/dolanmiu/docx/blob/master/demo/15-page-break-before.ts
|
||||||
|
|
||||||
## Page break control
|
## Page break control
|
||||||
|
|
||||||
|
21
docs/usage/sections.md
Normal file
21
docs/usage/sections.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Sections
|
||||||
|
|
||||||
|
> Every document is made up of one or more sections
|
||||||
|
|
||||||
|
A section is a grouping of paragraphs that have a specific set of properties used to define the pages on which the text will appear. Properties include page size, page numbers, page orientation, headers, borders and margins.
|
||||||
|
|
||||||
|
For example, you could have one section which is portrait with a header and footer, and another section in landscape with no footer, and a header showing the current page number.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
This creates a simple section in a document with one paragraph inside:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
@ -2,113 +2,147 @@
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const para = new Paragraph("To whom it may concern:").heading2().center();
|
const para = new Paragraph({
|
||||||
|
text: "To whom it may concern:",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
});
|
||||||
|
|
||||||
const name = new TextRun("Name:")
|
const name = new TextRun({
|
||||||
.bold()
|
text: "Name:",
|
||||||
.font("Calibri")
|
bold: true,
|
||||||
.allCaps();
|
font: "Calibri",
|
||||||
|
allCaps: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Available methods
|
## Available Options
|
||||||
|
|
||||||
* For run formatting:
|
### Run formatting
|
||||||
* `.bold()`, `.italic()`, `.smallCaps()`, `.allCaps()`, `.strike()`, `.doubleStrike()`, `.subScript()`, `.superScript()`: Set the formatting property to true
|
|
||||||
* `.underline(style="single", color=null)`: Set the underline style and color
|
|
||||||
* `.color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`)
|
|
||||||
* `.size(halfPts)`: Set the font size, measured in half-points
|
|
||||||
* `.font(name)`: Set the run's font
|
|
||||||
* `.style(name)`: Apply a named run style
|
|
||||||
* `.characterSpacing(value)`: Set the character spacing adjustment (in TWIPs)
|
|
||||||
* For paragraph formatting:
|
|
||||||
* `.heading1()`, `.heading2()`, `.heading3()`, `.heading4()`, `.heading5()`, `.title()`: apply the appropriate style to the paragraph
|
|
||||||
* `.left()`, `.center()`, `.right()`, `.justified()`: set the paragraph's alignment
|
|
||||||
* `.thematicBreak()`, `.pageBreak()`: Insert a thick rule or a page break beneath the paragraph
|
|
||||||
* `.leftTabStop(position)`: Add a left tab stop (measured in TWIPs from the left)
|
|
||||||
* `.maxRightTabStop()`: Add a right tab stop at the far right
|
|
||||||
* `.bullet()`: Use the default bullet style
|
|
||||||
* `.setNumbering(numbering, indentLevel)`: Use a custom numbering format for the paragraph
|
|
||||||
* `.style(name)`: Apply a named paragraph style
|
|
||||||
* `.indent(start, hanging=0)`: Set the paragraph's indent level (in TWIPs)
|
|
||||||
* `.spacing({before=0, after=0, line=0})`: Set the line and before/after on the paragraph. Before/after is measured in TWIPs, line is measured in 240ths of a line
|
|
||||||
|
|
||||||
Paragraph styles have all the run formatting methods, except `style()`, and `.left()`, `.center()`, `.right()`, `.justified()`, `.thematicBreak()`, `.leftTabStop(position)`, `.maxRightTabStop()`, `.indent(start, hanging=0)`, and `.spacing({before=0, after=0, line=0})` methods.
|
- `bold`, `italics`, `smallCaps`, `allCaps`, `strike`, `doubleStrike`, `subScript`, `superScript`: Set the formatting property to true
|
||||||
|
- `underline(style="single", color=null)`: Set the underline style and color
|
||||||
|
- `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`)
|
||||||
|
- `size(halfPts)`: Set the font size, measured in half-points
|
||||||
|
- `font(name)`: Set the run's font
|
||||||
|
- `style(name)`: Apply a named run style
|
||||||
|
- `characterSpacing(value)`: Set the character spacing adjustment (in TWIPs)
|
||||||
|
|
||||||
|
### Paragraph formatting
|
||||||
|
|
||||||
|
- `heading1`, `heading2`, `heading3`, `heading4`, `heading5`, `title`: apply the appropriate style to the paragraph
|
||||||
|
- `left`, `center`, `right`, `justified`: set the paragraph's alignment
|
||||||
|
- `thematicBreak`, `pageBreak`: Insert a thick rule or a page break beneath the paragraph
|
||||||
|
- `leftTabStop(position)`: Add a left tab stop (measured in TWIPs from the left)
|
||||||
|
- `maxRightTabStop`: Add a right tab stop at the far right
|
||||||
|
- `bullet`: Use the default bullet style
|
||||||
|
- `setNumbering(numbering, indentLevel)`: Use a custom numbering format for the paragraph
|
||||||
|
- `style(name)`: Apply a named paragraph style
|
||||||
|
- `indent(start, hanging=0)`: Set the paragraph's indent level (in TWIPs)
|
||||||
|
- `spacing({before=0, after=0, line=0})`: Set the line and before/after on the paragraph. Before/after is measured in TWIPs, line is measured in 240ths of a line
|
||||||
|
|
||||||
|
Paragraph styles have all the run formatting methods, except `style()`, and `left()`, `center()`, `right()`, `justified()`, `thematicBreak()`, `leftTabStop(position)`, `maxRightTabStop()`, `indent(start, hanging=0)`, and `spacing({before=0, after=0, line=0})` methods.
|
||||||
|
|
||||||
## Detailed guide
|
## Detailed guide
|
||||||
|
|
||||||
There are 4 items in DOCX that can be styled:
|
There are 4 items in `docx` that can be styled:
|
||||||
|
|
||||||
* Characters: Attributes that can change within a paragraph. e.g., bold, italics, etc.
|
- Characters: Attributes that can change within a paragraph. e.g., bold, italics, etc.
|
||||||
* Paragraphs: Attributes like indent, text alignment, line spacing, etc.
|
- Paragraphs: Attributes like indent, text alignment, line spacing, etc.
|
||||||
* Tables: Border styles, table formats, etc.
|
- Tables: Border styles, table formats, etc.
|
||||||
* List items: These are the numbers and bullets that are automatically inserted
|
- List items: These are the numbers and bullets that are automatically inserted
|
||||||
|
|
||||||
There are a few different ways of styling this content in DOCX, which somewhat resemble the HTML/CSS approach. In order of greatest to lowest priority:
|
There are a few different ways of styling this content in `docx`, which somewhat resemble the HTML/CSS approach. In order of greatest to lowest priority:
|
||||||
|
|
||||||
1. Direct formatting (AKA inline formatting)
|
1. Direct formatting (inline formatting)
|
||||||
2. Centrally defined styles (similar to external CSS)
|
2. Declaritive Styles (similar to external CSS)
|
||||||
3. Document defaults (similar to a `*` rule in CSS)
|
3. Document defaults (similar to a `*` rule in CSS)
|
||||||
|
|
||||||
Unlike CSS, less specific rules don't _necessarily_ override parent rules. The rules are a bit wonky, but if you're interested, see the [advanced formatting section](#Advanced formatting).
|
Unlike CSS, less specific rules don't _necessarily_ override parent rules. The rules are a bit wonky, but if you're interested, see the [advanced formatting section](#Advanced formatting).
|
||||||
|
|
||||||
### Direct formatting (AKA inline formatting)
|
### Direct formatting (inline formatting)
|
||||||
|
|
||||||
This is the type of formatting that your uncle uses when he types out documents: _N ... a ... m ... e ... :_ Then he grabs the mouse, highlights _Name:_ and moves over to the **B** for bold. This manner of formatting results in markup that is similar to writing `<span style="bold: true">Name:</span>` if you were typing out HTML. DOCX (the format) allows you to specify this for any of the four types of items. `docx` (the library) only supports this type of formatting for paragraphs and characters, using a _fluent_ api. Thus you could do:
|
This is the type of formatting that your uncle uses when he types out documents: _N ... a ... m ... e ... :_ Then he grabs the mouse, highlights _Name:_ and moves over to the **B** for bold. This manner of formatting results in markup that is similar to writing `<span style="bold: true">Name:</span>` if you were typing out HTML. `docx` (the format) allows you to specify this for any of the four types of items. `docx` (the library) only supports this type of formatting for paragraphs and characters, using a _fluent_ api. Thus you could do:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const name = new TextRun("Name:")
|
const name = new TextRun({
|
||||||
.bold()
|
text: "Name:",
|
||||||
.font("Calibri")
|
bold: true,
|
||||||
.allCaps();
|
font: "Calibri",
|
||||||
|
allCaps: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Or for paragraph formatting:
|
Or for paragraph formatting:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const para = new Paragraph("To whom it may concern:").heading2().center();
|
const para = new Paragraph({
|
||||||
|
text: "To whom it may concern:",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Centrally defined styles (similar to external CSS)
|
### Declaritive Styles (similar to external CSS)
|
||||||
|
|
||||||
DOCX files contain a styles section separate from the main content, much like how HTML includes CSS files. Unlike CSS, DOCX distinguishes between styles meant for tables (which show up in the table formatting toolbar), styles for lists (which show up under bullets and numbering), and styles for runs and paragraphs, which show up as dropdowns offering standard styles, like "Heading 1", "Caption", or any custom styles defined in that document. <!-- TODO: add pictures of the panes -->. `docx` allows you to define these styles using a fluent interface as well.
|
`docx` files contain a styles section separate from the main content, much like how HTML includes CSS files. Unlike CSS, `docx` distinguishes between styles meant for tables (which show up in the table formatting toolbar), styles for lists (which show up under bullets and numbering), and styles for runs and paragraphs, which show up as dropdowns offering standard styles, like "Heading 1", "Caption", or any custom styles defined in that document. <!-- TODO: add pictures of the panes -->. `docx` allows you to define these styles using a fluent interface as well.
|
||||||
|
|
||||||
There are three parts to using custom styles with `docx`:
|
To add styles, define your custom styles in the `document`:
|
||||||
|
|
||||||
1. Create a container object for the style definitions:
|
```ts
|
||||||
```js
|
|
||||||
const myStyles = new docx.Styles();
|
|
||||||
```
|
|
||||||
2. Define your custom styles, similar to the way you would format a paragraph or run
|
|
||||||
|
|
||||||
```js
|
|
||||||
// The first argument is an ID you use to apply the style to paragraphs
|
// The first argument is an ID you use to apply the style to paragraphs
|
||||||
// The second argument is a human-friendly name to show in the UI
|
// The second argument is a human-friendly name to show in the UI
|
||||||
myStyles
|
const doc = new Document({
|
||||||
.createParagraphStyle("myWonkyStyle", "My Wonky Style")
|
creator: "Clippy",
|
||||||
.basedOn("Normal")
|
title: "Sample Document",
|
||||||
.next("Normal")
|
description: "A brief example of using docx",
|
||||||
.color("999999")
|
styles: {
|
||||||
.italics()
|
paragraphStyles: [
|
||||||
.indent(720) // 720 TWIP === 720 / 20 pt === .5 in
|
{
|
||||||
.spacing({ line: 276 }); // 276 / 240 = 1.15x line spacing
|
id: "myWonkyStyle",
|
||||||
|
name: "My Wonky Style",
|
||||||
myStyles
|
basedOn: "Normal",
|
||||||
.createParagraphStyle("Heading2", "Heading 2")
|
next: "Normal",
|
||||||
.basedOn("Normal")
|
quickFormat: true,
|
||||||
.next("Normal")
|
run: {
|
||||||
.quickFormat()
|
italics: true,
|
||||||
.size(26) // 26 half-points === 13pt font
|
color: "999999",
|
||||||
.bold()
|
},
|
||||||
.underline("double", "FF0000")
|
paragraph: {
|
||||||
.spacing({ before: 240, after: 120 }); // TWIP for both
|
spacing: {
|
||||||
```
|
line: 276,
|
||||||
|
},
|
||||||
3. When you generate your document, make sure to pass the `styles` container to the `Packer`:
|
indent: {
|
||||||
|
left: 720,
|
||||||
```js
|
},
|
||||||
const packer = new Packer(doc, myStyles);
|
},
|
||||||
packer.pack(myOutStream);
|
},
|
||||||
|
{
|
||||||
|
id: "Heading2",
|
||||||
|
name: "Heading 2",
|
||||||
|
basedOn: "Normal",
|
||||||
|
next: "Normal",
|
||||||
|
quickFormat: true,
|
||||||
|
run: {
|
||||||
|
size: 26
|
||||||
|
bold: true,
|
||||||
|
color: "999999",
|
||||||
|
{
|
||||||
|
type: UnderlineType.DOUBLE,
|
||||||
|
color: "FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
spacing: {
|
||||||
|
before: 240,
|
||||||
|
after: 120
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up unstyled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
**Note**: If you are using the `.headingX` or `.title` methods of paragraphs, you must make sure to define `HeadingX` or `Title` styles for these. Otherwise they'll show up unstyled :(. If you are using the `.bullet` or `.setNumbering` methods, you need to define a `ListParagraph` style or the numbers may not show up.
|
||||||
@ -145,19 +179,29 @@ To determine the value of a styling property, you must first identify whether it
|
|||||||
|
|
||||||
The following properties are treated in a special manner; they're called toggle properties:
|
The following properties are treated in a special manner; they're called toggle properties:
|
||||||
|
|
||||||
* Bold
|
- Bold
|
||||||
* All caps
|
- All caps
|
||||||
* Small caps
|
- Small caps
|
||||||
* Italics
|
- Italics
|
||||||
* Single strike-through
|
- Single strike-through
|
||||||
* Hidden
|
- Hidden
|
||||||
* Imprint
|
- Imprint
|
||||||
* Emboss
|
- Emboss
|
||||||
* Character outline
|
- Character outline
|
||||||
* Character shadow
|
- Character shadow
|
||||||
|
|
||||||
For these properties, the rules state the following conflict resolution in case the property is specified at multiple points for the same item:
|
For these properties, the rules state the following conflict resolution in case the property is specified at multiple points for the same item:
|
||||||
|
|
||||||
* Direct formatting trumps all if specified (either true or false)
|
- Direct formatting trumps all if specified (either true or false)
|
||||||
* Otherwise, if the property is true in document defaults, the property is set to true
|
- Otherwise, if the property is true in document defaults, the property is set to true
|
||||||
* Otherwise, the property's value is an XOR of its effective table, paragraph, and character values. (So specifying bold `true` on a table style and a paragraph style would result in non-bold text if a paragraph inside the table had that style)
|
- Otherwise, the property's value is an XOR of its effective table, paragraph, and character values. (So specifying bold `true` on a table style and a paragraph style would result in non-bold text if a paragraph inside the table had that style)
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Declaritive styles
|
||||||
|
|
||||||
|
Importing Images from file system path
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/2-declaritive-styles.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/2-declaritive-styles.ts_
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
Read the styles using `fs`, and put it into the `Document` object in the constructor:
|
Read the styles using `fs`, and put it into the `Document` object in the constructor:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const styles = fs.readFileSync("./styles.xml", "utf-8");
|
const styles = fs.readFileSync("./styles.xml", "utf-8");
|
||||||
const doc = new docx.Document({
|
const doc = new docx.Document({
|
||||||
title: "Title",
|
title: "Title",
|
||||||
@ -34,14 +34,14 @@ const doc = new docx.Document({
|
|||||||
|
|
||||||
You can use paragraphs, `heading1()`, `heading2()` etc and it will be styled according to your `styles.xml` created earlier. You can even use your new style you made by calling the `style` method:
|
You can use paragraphs, `heading1()`, `heading2()` etc and it will be styled according to your `styles.xml` created earlier. You can even use your new style you made by calling the `style` method:
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
doc.createParagraph("Cool Heading Text").heading1();
|
doc.createParagraph("Cool Heading Text").heading1();
|
||||||
|
|
||||||
let paragraph = new docx.Paragraph('This is a custom named style from the template "Cool New Style"');
|
const paragraph = new docx.Paragraph('This is a custom named style from the template "Cool New Style"');
|
||||||
paragraph.style("Cool New Style");
|
paragraph.style("Cool New Style");
|
||||||
doc.addParagraph(paragraph);
|
doc.add(paragraph);
|
||||||
|
|
||||||
doc.createParagraph("Some normal text");
|
doc.createParagraph("Some normal text");
|
||||||
```
|
```
|
||||||
|
|
||||||
Example: https://github.com/dolanmiu/docx/blob/master/demo/demo13.js
|
Example: https://github.com/dolanmiu/docx/blob/master/demo/13-xml-styles.ts
|
||||||
|
53
docs/usage/symbols.md
Normal file
53
docs/usage/symbols.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Symbol Runs
|
||||||
|
|
||||||
|
!> SymbolRuns require an understanding of [Paragraphs](paragraph.md).
|
||||||
|
|
||||||
|
You can add multiple `symbol runs` in `Paragraphs` along with [text runs](text.md) using the Paragraph's `children` property.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph, TextRun, SymbolRun } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a checkbox: "),
|
||||||
|
new SymbolRun("F071")
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Specifying symbol font
|
||||||
|
|
||||||
|
By default symbol runs will use the `Wingdings` font. To switch fonts, pass an object instead of a string to the `SymbolRun` constructor and specify `char` and `symbolfont` properties:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const symbol = new SymbolRun({
|
||||||
|
char: "F071",
|
||||||
|
symbolfont: "Arial",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example symbols
|
||||||
|
|
||||||
|
Symbols are specified by their hexidecimal code. Ref http://officeopenxml.com/WPtextSpecialContent-symbol.php. Below are some examples.
|
||||||
|
|
||||||
|
- `F071`: empty checkbox
|
||||||
|
- `F043`: thumbs up
|
||||||
|
- `F04A`: smile
|
||||||
|
- `F04C`: frown
|
||||||
|
- `F022`: scissors
|
||||||
|
- `F0F0`: right arrow
|
||||||
|
- `F0FE`: checked box
|
||||||
|
|
||||||
|
## Typographical Emphasis
|
||||||
|
|
||||||
|
Symbol runs can have their display modified just like text runs. For example, they can be bolded and italicized:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const symbol = new SymbolRun({
|
||||||
|
char: "F071",
|
||||||
|
bold: true,
|
||||||
|
italics: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [text run](text.md) documentation for more info.
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
> Tab stops are useful, if you are unclear of what they are, [here is a link explaining](https://en.wikipedia.org/wiki/Tab_stop). It enables side by side text which is nicely laid out without the need for tables, or constantly pressing space bar.
|
||||||
|
|
||||||
**Note**: At the moment, the unit of measurement for a tab stop is counter intuitive for a human. It is using OpenXMLs own measuring system. For example, 2268 roughly translates to 3cm. Therefore in the future, I may consider changing it to percentages or even cm.
|
!> **Note**: The unit of measurement for a tab stop is in [DXA](https://stackoverflow.com/questions/14360183/default-wordml-unit-measurement-pixel-or-point-or-inches)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -10,45 +10,112 @@ Simply call the relevant methods on the paragraph listed below. Then just add a
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
var paragraph = new docx.Paragraph().maxRightTabStop();
|
const paragraph = new Paragraph({
|
||||||
var leftText = new docx.TextRun("Hey everyone").bold();
|
children: [new TextRun("Hey everyone").bold(), new TextRun(\t"11th November 1999")],
|
||||||
var rightText = new docx.TextRun("11th November 2015").tab();
|
tabStops: [
|
||||||
paragraph.addRun(leftText);
|
{
|
||||||
paragraph.addRun(rightText);
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. YUK!
|
|
||||||
|
|
||||||
```js
|
The example above will create a left aligned text, and a right aligned text on the same line. The laymans approach to this problem would be to either use text boxes or tables. Not ideal!
|
||||||
var paragraph = new docx.Paragraph();
|
|
||||||
paragraph.maxRightTabStop();
|
```ts
|
||||||
paragraph.leftTabStop(1000);
|
const paragraph = new Paragraph({
|
||||||
var text = new docx.TextRun("Second tab stop here I come!").tab().tab();
|
children: [new TextRun("Second tab stop here I come!")],
|
||||||
paragraph.addRun(text);
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TabStopType.LEFT,
|
||||||
|
position: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
The above shows the use of two tab stops, and how to select/use it.
|
The above shows the use of two tab stops, and how to select/use it.
|
||||||
|
|
||||||
## Left Tab Stop
|
You can add multiple tab stops of the same `type` too.
|
||||||
```js
|
|
||||||
paragraph.leftTabStop(2268);
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [new TextRun("Multiple tab stops!")],
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Left Tab Stop
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.LEFT,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
2268 is the distance from the left side.
|
2268 is the distance from the left side.
|
||||||
|
|
||||||
## Center Tab Stop
|
## Center Tab Stop
|
||||||
```js
|
|
||||||
paragraph.centerTabStop(2268);
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.CENTER,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
2268 is the distance from the left side.
|
|
||||||
|
2268 is the distance from the center.
|
||||||
|
|
||||||
## Right Tab Stop
|
## Right Tab Stop
|
||||||
```js
|
|
||||||
paragraph.rightTabStop(2268);
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: 2268,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
2268 is the distance from the left side.
|
|
||||||
|
2268 is the distance fro0oum the left side.
|
||||||
|
|
||||||
## Max Right Tab Stop
|
## Max Right Tab Stop
|
||||||
```js
|
|
||||||
paragraph.maxRightTabStop();
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
tabStops: [
|
||||||
|
{
|
||||||
|
type: TabStopType.RIGHT,
|
||||||
|
position: TabStopPosition.MAX,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
This will create a tab stop on the very edge of the right hand side. Handy for right aligning and left aligning text on the same line.
|
||||||
|
@ -12,11 +12,11 @@ The complete documentation can be found [here](https://www.ecma-international.or
|
|||||||
|
|
||||||
All you need to do is create a `TableOfContents` object and assign it to the document.
|
All you need to do is create a `TableOfContents` object and assign it to the document.
|
||||||
|
|
||||||
```js
|
```ts
|
||||||
const toc = new TableOfContents("Summary", {
|
const toc = new TableOfContents("Summary", {
|
||||||
hyperlink: true,
|
hyperlink: true,
|
||||||
headingStyleRange: "1-5",
|
headingStyleRange: "1-5",
|
||||||
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)]
|
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addTableOfContents(toc);
|
doc.addTableOfContents(toc);
|
||||||
@ -27,8 +27,8 @@ doc.addTableOfContents(toc);
|
|||||||
Here is the list of all options that you can use to generate your tables of contents:
|
Here is the list of all options that you can use to generate your tables of contents:
|
||||||
|
|
||||||
| Option | Type | TOC Field Switch | Description |
|
| Option | Type | TOC Field Switch | Description |
|
||||||
| --- | --- | --- | --- |
|
| ------------------------------- | ------------ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|captionLabel|string|`\a`|Includes captioned items, but omits caption labels and numbers. The identifier designated by `text` in this switch's field-argument corresponds to the caption label. Use ``\c`` to build a table of captions with labels and numbers.|
|
| captionLabel | string | `\a` | Includes captioned items, but omits caption labels and numbers. The identifier designated by `text` in this switch's field-argument corresponds to the caption label. Use `\c` to build a table of captions with labels and numbers. |
|
||||||
| entriesFromBookmark | string | `\b` | Includes entries only from the portion of the document marked by the bookmark named by `text` in this switch's field-argument. |
|
| entriesFromBookmark | string | `\b` | Includes entries only from the portion of the document marked by the bookmark named by `text` in this switch's field-argument. |
|
||||||
| captionLabelIncludingNumbers | string | `\c` | Includes figures, tables, charts, and other items that are numbered by a SEQ field (§17.16.5.56). The sequence identifier designated by `text` in this switch's field-argument, which corresponds to the caption label, shall match the identifier in the corresponding SEQ field. |
|
| captionLabelIncludingNumbers | string | `\c` | Includes figures, tables, charts, and other items that are numbered by a SEQ field (§17.16.5.56). The sequence identifier designated by `text` in this switch's field-argument, which corresponds to the caption label, shall match the identifier in the corresponding SEQ field. |
|
||||||
| sequenceAndPageNumbersSeparator | string | `\d` | When used with `\s`, the `text` in this switch's field-argument defines the separator between sequence and page numbers. The default separator is a hyphen (-). |
|
| sequenceAndPageNumbersSeparator | string | `\d` | When used with `\s`, the `text` in this switch's field-argument defines the separator between sequence and page numbers. The default separator is a hyphen (-). |
|
||||||
@ -47,30 +47,6 @@ Here is the list of all options that you can use to generate your tables of cont
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```js
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/28-table-of-contents.ts ':include')
|
||||||
// Let's define the options for generate a TOC for heading 1-5 and MySpectacularStyle,
|
|
||||||
// making the entries be hyperlinks for the paragraph
|
|
||||||
const toc = new TableOfContents("Summary", {
|
|
||||||
hyperlink: true,
|
|
||||||
headingStyleRange: "1-5",
|
|
||||||
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)]
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.addTableOfContents(toc);
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/28-table-of-contents.ts_
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("Header #1").heading1().pageBreakBefore());
|
|
||||||
doc.addParagraph(new Paragraph("I'm a little text, very nicely written.'"));
|
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("Header #2").heading1().pageBreakBefore());
|
|
||||||
doc.addParagraph(new Paragraph("I'm another text very nicely written.'"));
|
|
||||||
doc.addParagraph(new Paragraph("Header #2.1").heading2());
|
|
||||||
doc.addParagraph(new Paragraph("I'm another text very nicely written.'"));
|
|
||||||
|
|
||||||
doc.addParagraph(new Paragraph("My Spectacular Style #1").style("MySpectacularStyle").pageBreakBefore());
|
|
||||||
```
|
|
||||||
|
|
||||||
### Complete example
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo28.ts ":include")
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo28.ts_
|
|
||||||
|
387
docs/usage/tables.md
Normal file
387
docs/usage/tables.md
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
# Tables
|
||||||
|
|
||||||
|
!> Paragraphs requires an understanding of [Sections](usage/sections.md).
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
* `Tables` contain a list of `Rows`
|
||||||
|
* `Rows` contain a list of `TableCells`
|
||||||
|
* `TableCells` contain a list of `Parahraphs` and/or `Tables`. You can add `Tables` as tables can be nested inside each other
|
||||||
|
|
||||||
|
Create a simple table like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table({
|
||||||
|
rows: [Array of `TableRow`s]
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add the table in the `section`
|
||||||
|
|
||||||
|
```ts
|
||||||
|
doc.addSection({
|
||||||
|
children: [table],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Table
|
||||||
|
|
||||||
|
### Set Width
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table({
|
||||||
|
...,
|
||||||
|
width: {
|
||||||
|
size: [TABLE_WIDTH],
|
||||||
|
type: WidthType,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
...,
|
||||||
|
width: {
|
||||||
|
size: 4535,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pagination
|
||||||
|
|
||||||
|
#### Prevent row pagination
|
||||||
|
|
||||||
|
To prevent breaking contents of a row across multiple pages, call `cantSplit`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table({
|
||||||
|
rows: [],
|
||||||
|
cantSplit: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Table Row
|
||||||
|
|
||||||
|
A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const tableRow = new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Or preferably, add the tableRow directly into the `table` without declaring a variable:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
Here is a list of options you can add to the `table row`:
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| ----------- | ------------------------------------- | -------- |
|
||||||
|
| children | `Array<TableCell>` | Required |
|
||||||
|
| cantSplit | `boolean` | Optional |
|
||||||
|
| tableHeader | `boolean` | Optional |
|
||||||
|
| height | `{ value: number, rule: HeightRule }` | Optional |
|
||||||
|
|
||||||
|
### Repeat row
|
||||||
|
|
||||||
|
If a table is paginated on multiple pages, it is possible to repeat a row at the top of each new page by setting `tableHeader` to `true`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const row = new TableRow({
|
||||||
|
...,
|
||||||
|
tableHeader: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Table Cells
|
||||||
|
|
||||||
|
Cells need to be added in the `table row`, you can create a table cell like:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const tableCell = new TableCell({
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Or preferably, add the tableRow directly into the `table row` without declaring a variable:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const tableRow = new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| ------------- | ----------------------------------- | ----------------------------------------------------------- |
|
||||||
|
| children | `Array<Paragraph | Table>` | Required. You can nest tables by adding a table into a cell |
|
||||||
|
| shading | `ITableShadingAttributesProperties` | Optional |
|
||||||
|
| margins | `ITableCellMarginOptions` | Optional |
|
||||||
|
| verticalAlign | `VerticalAlign` | Optional |
|
||||||
|
| columnSpan | `number` | Optional |
|
||||||
|
| rowSpan | `number` | Optional |
|
||||||
|
| borders | `BorderOptions` | Optional |
|
||||||
|
| width | `{ size: number type: WidthType }` | Optional |
|
||||||
|
|
||||||
|
#### Border Options
|
||||||
|
|
||||||
|
| Property | Type | Notes |
|
||||||
|
| -------- | ----------------------------------------------------- | -------- |
|
||||||
|
| top | `{ style: BorderStyle, size: number, color: string }` | Optional |
|
||||||
|
| bottom | `{ style: BorderStyle, size: number, color: string }` | Optional |
|
||||||
|
| left | `{ style: BorderStyle, size: number, color: string }` | Optional |
|
||||||
|
| right | `{ style: BorderStyle, size: number, color: string }` | Optional |
|
||||||
|
|
||||||
|
##### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_DOT_STROKED,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.THICK_THIN_MEDIUM_GAP,
|
||||||
|
size: 5,
|
||||||
|
color: "889900",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Google DOCS
|
||||||
|
|
||||||
|
Google DOCS does not support start and end borders, instead they use left and right borders. So to set left and right borders for Google DOCS you should use:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DOT_DOT_DASH,
|
||||||
|
size: 3,
|
||||||
|
color: "green",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DOT_DOT_DASH,
|
||||||
|
size: 3,
|
||||||
|
color: "ff8000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add paragraph to a cell
|
||||||
|
|
||||||
|
Once you have got the cell, you can add data to it:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Set width of a cell
|
||||||
|
|
||||||
|
You can specify the width of a cell using:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
width: {
|
||||||
|
size: number,
|
||||||
|
type: WidthType,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`WidthType` values can be:
|
||||||
|
|
||||||
|
| Property | Notes |
|
||||||
|
| -------- | --------------------------------- |
|
||||||
|
| AUTO | |
|
||||||
|
| DXA | value is in twentieths of a point |
|
||||||
|
| NIL | is considered as zero |
|
||||||
|
| PCT | percent of table width |
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
cell.Properties.setWidth(100, WidthType.DXA);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Nested Tables
|
||||||
|
|
||||||
|
To have a table within a table, simply add it in the `children` block of a `table cell`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
children: [new Table(...)],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vertical Align
|
||||||
|
|
||||||
|
Sets the vertical alignment of the contents of the cell
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
verticalAlign: VerticalAlign,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
`VerticalAlign` values can be:
|
||||||
|
|
||||||
|
| Property | Notes |
|
||||||
|
| -------- | ------------------------------------------ |
|
||||||
|
| BOTTOM | Align the contents on the bottom |
|
||||||
|
| CENTER | Align the contents on the center |
|
||||||
|
| TOP | Align the contents on the top. The default |
|
||||||
|
|
||||||
|
For example, to center align a cell:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Merging cells together
|
||||||
|
|
||||||
|
### Row Merge
|
||||||
|
|
||||||
|
When cell rows are merged, it counts as multiple rows, so be sure to remove excess cells. It is similar to how HTML's `rowspan` works.
|
||||||
|
https://www.w3schools.com/tags/att_td_rowspan.asp
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
rowSpan: [NUMBER_OF_CELLS_TO_MERGE],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
The example will merge three rows together.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
rowSpan: 3,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Column Merge
|
||||||
|
|
||||||
|
When cell columns are merged, it counts as multiple columns, so be sure to remove excess cells. It is similar to how HTML's `colspan` works.
|
||||||
|
https://www.w3schools.com/tags/att_td_colspan.asp
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
columnSpan: [NUMBER_OF_CELLS_TO_MERGE],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
The example will merge three columns together.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const cell = new TableCell({
|
||||||
|
...,
|
||||||
|
columnSpan: 3,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/4-basic-table.ts_
|
||||||
|
|
||||||
|
### Custom borders
|
||||||
|
|
||||||
|
Example showing how to add colourful borders to tables
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/20-table-cell-borders.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/20-table-cell-borders.ts_
|
||||||
|
|
||||||
|
### Adding images
|
||||||
|
|
||||||
|
Example showing how to add images to tables
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/24-images-to-table-cell.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/24-images-to-table-cell.ts_
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/36-image-to-table-cell.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/36-image-to-table-cell.ts_
|
||||||
|
|
||||||
|
### Alignment of text in a cell
|
||||||
|
|
||||||
|
Example showing how align text in a table cell
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/31-tables.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/31-tables.ts_
|
||||||
|
|
||||||
|
### Shading
|
||||||
|
|
||||||
|
Example showing merging of columns and rows and shading
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/32-merge-and-shade-table-cells.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/32-merge-and-shade-table-cells.ts_
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/41-merge-table-cells-2.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/41-merge-table-cells-2.ts_
|
||||||
|
|
||||||
|
### Merging columns
|
||||||
|
|
||||||
|
Example showing merging of columns and rows
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/43-images-to-table-cell-2.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/43-images-to-table-cell-2.ts_
|
||||||
|
|
||||||
|
### Floating tables
|
||||||
|
|
||||||
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/34-floating-tables.ts ':include')
|
||||||
|
|
||||||
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/34-floating-tables.ts_
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user