Add footer tests and improve table documentation

This commit is contained in:
Dolan
2019-01-03 02:11:04 +00:00
parent b9465b2a20
commit 04ea2b2dc9
2 changed files with 42 additions and 11 deletions

View File

@ -2,15 +2,15 @@
You can create tables with `docx`. More information can be found [here](http://officeopenxml.com/WPtable.php). You can create tables with `docx`. More information can be found [here](http://officeopenxml.com/WPtable.php).
## How to ## Create Table
To create a table, simply use the `createTable` method on a `document`. To create a table, simply use the `createTable()` method on a `document`.
```ts ```ts
const table = doc.createTable([NUMBER OF ROWS], [NUMBER OF COLUMNS]); const table = doc.createTable([NUMBER OF ROWS], [NUMBER OF COLUMNS]);
``` ```
Alternatively, you can create a table object directly, and then add it in the document Alternatively, you can create a table object directly, and then add it in the `document`
```ts ```ts
const table = new Table(4, 4); const table = new Table(4, 4);
@ -36,10 +36,20 @@ The above section created a table with cells. To access the cell, use the `getCe
const cell = table.getCell([ROW INDEX], [COLUMN INDEX]); const cell = table.getCell([ROW INDEX], [COLUMN INDEX]);
``` ```
For example:
```ts ```ts
const cell = table.getCell(0, 2); const cell = table.getCell(0, 2);
``` ```
### Add paragraph to a cell
Once you have got the cell, you can add data to it with the `addParagraph` method.
```ts
cell.addParagraph(new Paragraph("Hello"));
```
## Borders ## Borders
BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`. BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`.
@ -107,14 +117,6 @@ To get a row, use the `getRow` method on a `table`. There are a handful of metho
table.getRow([ROW INDEX]); table.getRow([ROW INDEX]);
``` ```
### Add paragraph to a cell
Once you have got the cell, you can add data to it with the `addParagraph` method.
```ts
cell.addParagraph(new Paragraph("Hello"));
```
## Merge cells together ## Merge cells together
### Merging on a row ### Merging on a row

View File

@ -0,0 +1,29 @@
import { expect } from "chai";
import * as sinon from "sinon";
import { FooterWrapper } from "./footer-wrapper";
import { Media } from "./media";
import { Paragraph } from "./paragraph";
import { Table } from "./table";
describe("FooterWrapper", () => {
describe("#addParagraph", () => {
it("should call the underlying footer's addParagraph", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.Footer, "addParagraph");
file.addParagraph(new Paragraph());
expect(spy.called).to.equal(true);
});
});
describe("#addTable", () => {
it("should call the underlying footer's addParagraph", () => {
const file = new FooterWrapper(new Media(), 1);
const spy = sinon.spy(file.Footer, "addTable");
file.addTable(new Table(1, 1));
expect(spy.called).to.equal(true);
});
});
});