Retrieve Comments

This guide will show the process of retrieving comments from docx document using unioffice.

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

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

cd unioffice-examples/document/document/comment-list/

How it works

The example code starts by the import section followed by the init function in lines 9-25. With these the necessary dependencies are imported and the api key is set respectively.

The main function which contains the main code is defined in lines 27-72. It starts by checking the arguments given in the command line. In line 33, it sets the inputPath variable with the path to the docx file provided in the second argument. Line 35 opens this document using document.Open(inputPath). Line 42 checks if the document contains comments by calling the doc.HasComments() method. If the document has comments, they are retrieved using doc.Comments() in line 47. Then the multiple nested for loops in lines 52-72 iterates through each comment and print its content.

Got any Questions?

We're here to help you.