Tables in Word Documents with Node.js

Tables in Word Documents with Node.js

Add or delete a table, add a row or a column, extract data from a table, - all this and much more you can do with Word documents in Node.js with Cloud API.

If you have worked in Microsoft Word, then you understand the main concept of working with tables to create text and graphics or showing data in a tabular style (similar to a spreadsheet).
In a standard document page text, graphics and other content appear in a free-flowing way. The text and images wrap, and one item appears after the next. There is no way to control where items appear in the document, and this is where tables become useful. You can use a table to structure content, place text or images in one cell and align it accordingly. Furthermore, tables can be nested inside other tables up to any depth with Node.js API.

Note: As a prerequisite, you need Node.js and Words Cloud Node.js package installed on your computer.

Creating and Formatting Tables with Word

A table is made up of rows and columns. The intersection of a row and column is called a cell.
You can use Cloud API in Node.js to create a table, format it, apply a style, modify a table in code, insert data into rows and cells.
A table is imported as a Table node from any document loaded into the Cloud Storage. Aspose.Words.Tables namespace contains classes that represent tables, rows, cells and their formatting.

Table manipulation in Node.js

You can perform the following tasks with tables in DOCX, DOC, RTF and document file formats using Node.js:

  • Add or delete a table.
  • Resize a table.
  • Change columns width in a table.
  • Change rows height in a table.
  • Convert a table to text.
  • Text wrap to surround a picture or a diagram with text.
  • Add rows or columns to a Table.
  • Delete rows or columns in a Table.
  • Change properties of a table, a row or a cell.

Extract data from tables using Node.js

Node.js API allows you to extract text from tables. You can call API methods to get a row or to get a cell from a table.

Working with borders and margins

You can set border style, margins and cell padding in tables with Node.js API. You can use border property to set a border for a table. You can apply borders to a table, to each cell or to a single cell.
Cell margin represents the number of blank spaces between the content of a cell and the border of a cell. Usually, all cells have the same margin in the table.
Working with margins, give you the right way to control spacing in a Word table.

Table properties with Node.js API

A table has the following properties:


Resize a table, a column or a row using AutoFit option.
Turn on AutoFit to adjust tables or columns to fit the size of your content automatically. Otherwise, turn it off for Fixed Column Width option.


You can align a table between page margins either right, left, or center with Node.js API.

Merge a table

Node.js API allows you to merge two or more tables into one larger table. After merging tables, you can also merge specific cells within the table.

Split a table

It allows you to split a table into two or more tables. It creates smaller tables or adds text between two tables.

How to work with tables in a DOCX document in Node.js

  1. Go to the Aspose Cloud Dashboard.
  2. Create a new Account to access all applications and services or Sign In to your account.
  3. Click on Applications in the left menu to get Client Id and Client Secret.
  4. Check API Reference page for the description of APIs parameters.
  5. Install Nodejs package.
  6. Check Developer Guide to work with tables in a DOCX file in Node.js.

Working with tables in a Word document in Node.js
const { WordsApi, InsertTableRequest, TableInsert,
    GetTableWithoutNodePathRequest } = require("asposewordscloud");
var appSid = "####-####-####-####-####";
var appKey = "##################";

wordsApi = new WordsApi(appSid, appKey);

// Add a table      
var request = new InsertTableRequest({
    name: "empty.docx",
    nodePath: "sections/0",
    table: new TableInsert ({ columnsCount: 5, rowsCount: 3 })

// Extract data from a table
var request = new GetTableWithoutNodePathRequest({
    name: "empty.docx",
    index: 0
wordsApi.getTableWithoutNodePath(request).then((result) => {


Support and Learning Resources