Remove Comments
This guide will explain the process of removing comments from docx document using unioffice.
An example code from the unioffice-examples
repository will be used. But first, in order to follow along with this guide,
setting up the necessary environment is necessary.
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-remove/
folder in the unioffice-examples directory.
cd unioffice-examples/document/document/comment-remove/
How it works
Line 9-17
, the necessary libraries are imported. The init
function sets the API key using license.SetMeteredKey
. This API key is retrieved from the system environment.
The main
function is defined in lines 28-58
. The code accepts the file path and the ID of the comment to be removed via the command line arguments. For this reason, the number of command line arguments is checked in line 29-32
. Then in line the input path and comment id variables are set. In line 40
, the document is opened using document.Open(inputPath)
. Line 46
calls the listComment
function to display all the comments. This function is defined in lines 60-84
. And it was explained in this guide.
In line 48
, the comment is removed using doc.RemoveComment(int64(commentId))
. This call returns a status indicating whether the process was successful or not. Line 57
again calls the listComment
function to list the comments. This will help compare the comments before and after the removal process.