Bullet and Numbering
This guide will show you how to create and format bulleted and numbered lists.
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/bullet-and-numbering
folder in the unioffice-examples directory.
cd unioffice-examples/document/bullet-and-numbering/
How it works
Lines 4-12
import the UniOffice packages and other required dependencies.
The init function in lines 14-21
authenticates your request with your UNIDOC_LICENSE_API_KEY
.
A mapList variable is defined on lines 23-27
that contains a list of maps, each of which represents a list title and a list of elements associated with that title. This variable is used later to generate the bulleted and numbered lists in the document.
The main function in lines 29-106
creates a new document as doc and defines a new numbering style called nd
, with the decimal numbering format, left alignment, and an indent of 0.5 inches. It iterates through a loop where a paragraph is created, assigned the numbering style, and the text from the mapList
is added. Then, the process is repeated to create subpoints, but this time changing the numbering style and defining it as ndChildren
. This process is repeated several times in the code, each time changing the numbering style.
Run the code
Run this command to create a word page with bulleted and numbered lists. This will also get all the required dependencies to run the program.
go run main.go
Sample output
Open the output word document with Word and you will see a list of bullets with their numbering.