Tables in Word Documents with Dart/Flutter

Tables in Word Documents with Dart/Flutter

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 Dart 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 Dart API.

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 Dart 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 Dart

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

  • 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 Dart

Dart 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 Dart 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 Dart 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 Dart API.

Merge a table

Dart 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 Dart

  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. Add the latest version of Dart library.
  6. Check Developer Guide to work with tables in a DOCX file in Dart.

Working with tables in a Word document in Dart
import 'package:aspose_words_cloud/aspose_words_cloud.dart';

final clientId = '925a87ba-fbc1-49d2-8a1f-b718b43745e4';
final secret = '4c44f87e7102f1b9fa519894c1c662de';
var configuration = Configuration(secret, clientId);
var wordsApi = WordsApi(configuration);

// Add a table
var table = TableInsert();
table.columnsCount = 5;
table.rowsCount = 4;
var request1 = InsertTableRequest('sample.docx', table, nodePath: 'sections/0');

// Extract data from table
var request2 = GetTableRequest('sample.docx', 0);

// Edit a cell at row 2, column 3
var paragraph = ParagraphInsert();
paragraph.text = 'Lorem Ipsum';
var request3 = InsertParagraphRequest('sample.docx', paragraph, nodePath: 'sections/0/tables/0/rows/1/cells/2');


Support and Learning Resources