Turn methods into "add()"
This commit is contained in:
@ -39,7 +39,7 @@ var doc = new docx.Document();
|
||||
var paragraph = new docx.Paragraph("Some cool text here.");
|
||||
// Add more text into the paragraph if you wish
|
||||
paragraph.addRun(new docx.TextRun("Lorem Ipsum Foo Bar"));
|
||||
doc.addParagraph(paragraph);
|
||||
doc.add(paragraph);
|
||||
|
||||
// Used to export the file into a .docx file
|
||||
var packer = new docx.Packer();
|
||||
|
@ -92,7 +92,7 @@ This is just a guideline, and the rules can sometimes be broken.
|
||||
*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
|
||||
public addParagraph(paragraph: Paragraph) {
|
||||
public add(paragraph: Paragraph) {
|
||||
this.root.push(paragraph);
|
||||
}
|
||||
```
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
```
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user