How to Create and Format Bulleted and Numbered Lists
Lists are everywhere. From groceries to project plans, they make life easier. But when it comes to Word documents, not all lists are created equal.
Bulleted and numbered lists can make your document visually appealing, organized, and professional. Let’s explore how to create and format them using the UniOffice SDK. This guide is beginner-friendly, and yes, we’ll add some fun along the way.
Why Use Bulleted and Numbered Lists?
Lists serve more than aesthetics. Here’s why they’re essential:
Clarity: Break down information into digestible chunks.
Structure: Add hierarchy to your ideas.
Professionalism: Impress your audience with clean formatting.
Whether you’re writing a report or a to-do list, UniOffice has you covered.
Setting Up for Success
Before you dive into the code, a little prep work is needed.
Step 1: Get Your API Key
Visit UniCloud and sign up to get your free API key.
Step 2: Clone the Repository
Run these commands in your terminal:
git clone https://github.com/unidoc/unioffice-examples.git
cd unioffice-examples/document/bullet-and-numbering/
Step 3: Environment Setup
Follow the UniOffice setup guide to ensure everything is ready.
Code Walkthrough
Here’s how you can create bulleted and numbered lists with UniOffice.
Creating Bulleted Lists
package main
import (
"fmt"
"os"
"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/document"
)
func init() {
err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
if err != nil {
panic(err)
}
}
func main() {
doc := document.New()
defer doc.Close()
// Numbered List Setup
nd := doc.Numbering.AddDefinition()
lvl := nd.AddLevel()
lvl.SetFormat(wml.ST_NumberFormatDecimal)
lvl.SetAlignment(wml.ST_JcLeft)
lvl.Properties().SetLeftIndent(0.5 * measurement.Inch)
lvl.SetText("%1.")
para := doc.AddParagraph()
para.SetNumberingDefinition(nd)
para.SetNumberingLevel(0)
para.AddRun().AddText("Numbered List Item 1")
// Nested Numbered Lists
ndChildren := doc.Numbering.AddDefinition()
lvl = ndChildren.AddLevel()
lvl.SetFormat(wml.ST_NumberFormatLowerRoman)
lvl.Properties().SetLeftIndent(1 * measurement.Inch)
lvl.SetText("%1.")
subPara := doc.AddParagraph()
subPara.SetNumberingDefinition(ndChildren)
subPara.SetNumberingLevel(0)
subPara.AddRun().AddText("Nested Item i.")
// Bullet List Setup
ndBullet := doc.Numbering.Definitions()[0]
for i := 1; i <= 3; i++ {
bulPara := doc.AddParagraph()
bulPara.SetNumberingDefinition(ndBullet)
bulPara.SetNumberingLevel(i - 1)
bulPara.AddRun().AddText(fmt.Sprintf("Bullet Level %d", i))
}
doc.SaveToFile("bullet-and-numbering.docx")
}
Breaking Down the Code
Initialization
The
init
function sets up your API key. Without it, nothing works.Numbered List Creation
a. Add a numbering definition:
doc.Numbering.AddDefinition()
.b. Set properties like format, alignment, and indentation.
c. Apply the style using
SetNumberingDefinition()
.Nested Lists
Create subpoints with a different numbering style (e.g., Roman numerals).
Bulleted Lists
Use
doc.Numbering.Definitions()[0]
for bullet points and assign levels.Save the File
Export your masterpiece with
doc.SaveToFile()
.
Running the Code
Save your file as main.go
and execute this command:
go run main.go
You’ll find a Word document (bullet-and-numbering.docx
) with beautifully formatted lists in your directory.
Key Formatting Features
Indentation
Set the perfect alignment using:
lvl.Properties().SetLeftIndent(0.5 \* measurement.Inch)
Number Formats
Switch between decimal, Roman numerals, or custom formats:
lvl.SetFormat(wml.ST_NumberFormatDecimal)
lvl.SetFormat(wml.ST_NumberFormatLowerRoman)
Bullet Points
Use default definitions for simple and clean bullet styling:
ndBullet := doc.Numbering.Definitions()[0]
Real-World Applications
Business Documentation
Organize meeting minutes with nested numbered lists.
Academic Papers
Use bullet points for key points and Roman numerals for subsections.
Creative Projects
Make brainstormed ideas visually appealing and structured.
Pro Tips
Combine Styles: Mix numbered and bulleted lists for a unique hierarchy.
Use Nested Levels: Add depth to your lists by indenting subpoints.
Experiment with Formats: Try out different numbering styles for variety.
FAQs
Can I Add More Levels?
Yes! Just define additional levels in your numbering setup.
How Do I Customize Bullet Characters?
Modify the bullet properties in the Numbering.Definitions() configuration.
Can I Edit Lists in an Existing Document?
Absolutely. Load your document and apply similar methods.
Learn More
For more advanced formatting tips, check out:
Working with Numbering Examples
Conclusion
Lists are more than just a way to organize information—they’re an art form. With UniOffice, you can create, format, and customize bulleted and numbered lists effortlessly.
So, what are you waiting for? Grab your API key, fire up your terminal, and start creating documents that wow!