Update outdated docs to show current usage

This commit is contained in:
Tom Hunkapiller
2021-05-18 17:16:10 +03:00
parent bb8ac8b9d8
commit d527013451
2 changed files with 31 additions and 26 deletions

View File

@ -5,35 +5,49 @@
?> **Note:** This feature only works on Headers and Footers ?> **Note:** This feature only works on Headers and Footers
```ts ```ts
doc.Header.createParagraph().addRun(new TextRun("Page Number: ").pageNumber()).addRun(new TextRun("to ").numberOfTotalPages()); new Paragraph({
children: [
new TextRun({
children: ["Page #: ", PageNumber.CURRENT],
})
]
})
``` ```
## Current page number ## 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 ```ts
pageNumber(); PageNumber.CURRENT
``` ```
For example: For example:
```ts ```ts
const currentPageRun = new TextRun("Current Page Number: ").pageNumber(); new Paragraph({
paragraph.addRun(currentPageRun); children: [
new TextRun({
children: ["Page Number ", PageNumber.CURRENT],
})
]
})
``` ```
## Total number of pages ## Total number of pages
```ts ```ts
numberOfTotalPages(); PageNumber.TOTAL_PAGES
``` ```
For example: For example:
```ts ```ts
const lastPage = new TextRun("Total Page Number: ").numberOfTotalPages(); new Paragraph({
paragraph.addRun(lastPage); children: [
new TextRun({
children: ["Total Pages Number: ", PageNumber.TOTAL_PAGES],
})
]
})
``` ```
@ -42,17 +56,14 @@ paragraph.addRun(lastPage);
You can combine the two to get "Page 2 of 10" effect: You can combine the two to get "Page 2 of 10" effect:
```ts ```ts
const currentPageRun = new TextRun("Page ").pageNumber(); new Paragraph({
const lastPage = new TextRun("of ").numberOfTotalPages(); children: [
new TextRun("My awesome text here for my university dissertation. ")
paragraph.addRun(currentPageRun); new TextRun({
paragraph.addRun(lastPage); children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
``` })
]
Or: })
```ts
doc.Header.createParagraph().addRun(new TextRun("Page ").pageNumber()).addRun(new TextRun("of ").numberOfTotalPages());
``` ```
## Examples ## Examples

View File

@ -237,12 +237,6 @@ const cell = new TableCell({
| NIL | is considered as zero | | NIL | is considered as zero |
| PCT | percent of table width | | PCT | percent of table width |
#### Example
```ts
cell.Properties.setWidth(100, WidthType.DXA);
```
### Nested Tables ### Nested Tables
To have a table within a table, simply add it in the `children` block of a `table cell`: To have a table within a table, simply add it in the `children` block of a `table cell`: