Adding Paragraphs to Tables
This guide will demonstrate how to work with tables and paragraphs simultaneously.
Before you begin
You should get your API key from your UniCloud account.
If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unioffice-examples
Navigate to the path document/paragraphs_in_table
folder in the unioffice-examples directory.
cd unioffice-examples/document/paragraphs_in_table/
How it works
Lines 3-11
import the UniOffice packages and other required dependencies.
The init function in lines 13-20
authenticates your request with your UNIDOC_LICENSE_API_KEY
.
In the main function, spanning from line 22 to 53
, a new document is created. A new paragraph and some text are added in line 26
. Next, a table is created before the previous paragraph using the InsertTableAfter
method, and its borders are defined using the SetAll
method. A row with a cell is also added to the table, and within the cell, a new paragraph is added in line 30
, followed by the addition of a run and text.
A new paragraph is created after the table, and text is added to it. The same action is performed using the InsertParagraphAfter
method with the table as an attribute in line 36
.
In line 39
, a new paragraph is added before the table using the InsertParagraphBefore
method with the table as an attribute, and text is added to it.
Next, in line 42
, a new table is added after the paragraph added with InsertParagraphBefore
using the InsertTableAfter
method. Borders are configured in the following lines, and a paragraph is added inside it, just like in the first table created.
Finally, in line 47
, a table is added within the last table created using the InsertTableBefore
method with the paragraph from the previous table as a parameter. Borders are configured, and a paragraph with text is created within it.
The result is saved in line 52
.
Run the code
To generate a Word document containing various interconnected tables and paragraphs, execute the following command:
go run main.go