Turn methods into "add()"

This commit is contained in:
Dolan
2019-06-25 23:17:56 +01:00
parent 3ef8f5311d
commit e2574ec23b
55 changed files with 253 additions and 262 deletions

View File

@ -11,8 +11,8 @@ var paragraph = new docx.Paragraph(text).bullet();
var text2 = new docx.TextRun("Are awesome");
var paragraph2 = new docx.Paragraph(text2).bullet();
doc.addParagraph(paragraph);
doc.addParagraph(paragraph2);
doc.add(paragraph);
doc.add(paragraph2);
```
### This will produce:

View File

@ -23,7 +23,7 @@ var paragraph = new docx.Paragraph("Short hand notation for adding text.");
After you create the paragraph, you must add the paragraph into the `document`:
```js
doc.addParagraph(paragraph);
doc.add(paragraph);
```
## Styles

View File

@ -39,7 +39,7 @@ doc.createParagraph("Cool Heading Text").heading1();
let paragraph = new docx.Paragraph('This is a custom named style from the template "Cool New Style"');
paragraph.style("Cool New Style");
doc.addParagraph(paragraph);
doc.add(paragraph);
doc.createParagraph("Some normal text");
```

View File

@ -58,15 +58,15 @@ const toc = new TableOfContents("Summary", {
doc.addTableOfContents(toc);
doc.addParagraph(new Paragraph("Header #1").heading1().pageBreakBefore());
doc.addParagraph(new Paragraph("I'm a little text, very nicely written.'"));
doc.add(new Paragraph("Header #1").heading1().pageBreakBefore());
doc.add(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.add(new Paragraph("Header #2").heading1().pageBreakBefore());
doc.add(new Paragraph("I'm another text very nicely written.'"));
doc.add(new Paragraph("Header #2.1").heading2());
doc.add(new Paragraph("I'm another text very nicely written.'"));
doc.addParagraph(new Paragraph("My Spectacular Style #1").style("MySpectacularStyle").pageBreakBefore());
doc.add(new Paragraph("My Spectacular Style #1").style("MySpectacularStyle").pageBreakBefore());
```
### Complete example

View File

@ -4,10 +4,10 @@ You can create tables with `docx`. More information can be found [here](http://o
## Create Table
To create a table, simply create one with `new Table()`, then add it to the document: `doc.addTable()`.
To create a table, simply create one with `new Table()`, then add it to the document: `doc.add()`.
```ts
const table = doc.addTable(new Table({
const table = doc.add(new Table({
rows: [NUMBER OF ROWS],
columns: [NUMBER OF COLUMNS]
});
@ -17,7 +17,7 @@ Alternatively, you can create a table object directly, and then add it in the `d
```ts
const table = new Table(4, 4);
doc.addTable(table);
doc.add(table);
```
The snippet below creates a table of 2 rows and 4 columns.
@ -27,7 +27,7 @@ const table = new Table({
rows: 2,
columns: 4,
});
doc.addTable(table);
doc.add(table);
```
## Rows and Columns
@ -92,10 +92,10 @@ const cell = column.getCell(2);
### Add paragraph to a cell
Once you have got the cell, you can add data to it with the `addParagraph()` method.
Once you have got the cell, you can add data to it with the `add()` method.
```ts
cell.addParagraph(new Paragraph("Hello"));
cell.add(new Paragraph("Hello"));
```
### Set width of a cell
@ -226,7 +226,7 @@ It has not been implemented yet, but it will follow a similar structure as mergi
To have a table within a table
```ts
cell.addTable(new Table(1, 1));
cell.add(new Table(1, 1));
```
## Pagination