Node Combine

This guide demonstrates how to get document content as nodes from DOCX files and merge it into new document.

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

To get the example navigate to the path document/node-combine folder in the unioffice-examples directory.

cd unioffice-examples/document/node-combine/

Here are the two images from the two files that will be used in this example:

Sample 1 Page 1

Sample 2 Page 1

How it works

Lines 14-20 import the UniOffice packages and other required dependencies.

The init function in lines 22-29 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function spans from line 31 to 86. It begins by opening both documents until line 42. Subsequently, nodes from both documents are retrieved using the Nodes function, extending to line 47.

Next, a list of nodes is created using the FindNodeByCondition function in the first document, which returns all nodes that meet a specific condition. In this case, it searches for all elements of the table type (lines 51-57) and creates a new document to which all nodes from the node list are added using the AppendNode function within a loop in the lines 63-65.

Following that, the FindNodeByCondition function is once again employed to locate all nodes of the paragraph type in the second document and store them in another list, as shown in lines 69-75. Finally, these found nodes are added to the previously created document, and the new document is saved in line 82.

Run the code

Run this command to perform the node combine.

go run main.go

Sample output

Node Combine Result

Got any Questions?

We're here to help you.