Powerful Open-Source Word Processing Library for Go
Open Source Golang Library for Word document Automation Featuring Templates, Tables, Styles, Headers, Footers, and DOCX Generation.
What is WordZero?
wordZero is an open-source Golang library designed for creating, reading, editing, and managing Microsoft Word DOCX documents programmatically. It provides a clean API that allows developers to generate professional reports, invoices, contracts, documentation, and other business documents directly from Go applications. The library is built around the Office Open XML (OOXML) standard and offers extensive document manipulation capabilities, including text formatting, paragraph styling, table creation, image insertion, headers, footers, lists, templates, and table-of-contents generation. Its architecture focuses on performance, flexibility, and ease of use, making it suitable for both small projects and enterprise-level document automation systems.
Modern applications frequently require automated document generation. Whether you are building reporting systems, customer document portals, HR management platforms, or invoice generators, manually creating Word documents can be time-consuming and error-prone. wordZero solves this challenge by enabling developers to generate fully formatted DOCX files directly from code. The library supports structured document creation, reusable templates, advanced formatting, and dynamic content generation. This reduces manual effort, improves consistency, and helps organizations automate document-heavy workflows efficiently. Additionally, its support for styles, tables, headers, footers, and document metadata makes it possible to create professional-grade documents that closely resemble manually authored Word files.
Getting Started with wordZero
The recommended way to install the wordZero into your project is by using GitHub. Please use the following command for a smooth installation.
Install wordZero via GitHub
go get github.com/zerx-lab/wordZero
Create and Save Word Documents via Go API
One of the core capabilities of wordZero is its ability to create Word documents from scratch. Developers can initialize a new document, add content, and save it as a DOCX file within a few lines of code. This feature is extremely useful for automated reporting systems, document generation services, and applications that need to export user data into Microsoft Word format. Since the library handles OOXML packaging internally, developers can focus on content creation rather than dealing with complex document structures.
How to Create DOCX Files Programmatically via Go Library?
package main
import (
"github.com/ZeroHawkeye/wordZero/pkg/document"
)
func main() {
doc := document.New()
doc.AddParagraph("Welcome to wordZero!")
err := doc.Save("sample.docx")
if err != nil {
panic(err)
}
}
Advanced Template Engine with Inheritance
WordZero's template engine transforms how you generate dynamic documents. Unlike basic string replacement, it supports block-based inheritance, conditional rendering, loops, and image placeholders. This means you can create base templates (headers, footers, brand guidelines) and extend them for specific use cases like sales reports or invoices. It is very useful to eliminates code duplication and separates content from presentation. Marketing teams can update templates without developer intervention.
How to Generate Dynamic Documents via Templates inside Go Apps?
package main
import (
"log"
"github.com/zerx-lab/wordZero/pkg/document"
)
func main() {
engine := document.NewTemplateEngine()
// Base template with reusable blocks
baseTemplate := `{{companyName}} Report
{{#block "summary"}}Default summary{{/block}}
{{#block "content"}}Default content{{/block}}`
engine.LoadTemplate("base", baseTemplate)
// Child template overriding specific blocks
salesTemplate := `{{extends "base"}}
{{#block "summary"}}
Sales: {{revenue}} USD | Growth: {{growth}}%
{{/block}}`
engine.LoadTemplate("sales", salesTemplate)
data := document.NewTemplateData()
data.SetVariable("companyName", "Acme Corp")
data.SetVariable("revenue", "125000")
data.SetVariable("growth", "15")
doc, _ := engine.RenderTemplateToDocument("sales", data)
doc.Save("quarterly_report.docx")
}
Dynamic Native Image Management and Automatic Scaling
Integrating assets like charts, organizational branding, or photographs requires strict layout management to avoid ruining text wraps. The open source wordZero library features simple native wrappers that accept image inputs directly from physical system paths or in-memory byte arrays ([]byte). The library automatically detects aspect ratios, enabling functions like auto-fitting images to margins or explicit pixel restraints.
How to Manage Images inside Word Documents via Go Library?
package main
import (
"log"
"github.com/zerx-lab/wordZero/pkg/document"
)
func main() {
doc := document.New()
doc.AddParagraph("Visual Asset Documentation Summary")
// Insert an image path from your local deployment setup
image, err := doc.AddImageFromFile("company_logo.png")
if err != nil {
log.Fatalf("Unable to discover or parse local asset: %v", err)
}
// Constrain the target image properties while auto-fitting column margins safely
image.SetWidth(350)
image.FitToPageWidth()
if err := doc.Save("image_report.docx"); err != nil {
log.Fatalf("Error saving file payload: %v", err)
}
}
Markdown-to-Word Direct Conversions via Ruby Library?
In decentralized publishing pipelines, Markdown is often the preferred choice for writing content, while Word is required for corporate distribution. wordZero answers this need with a dedicated, built-in dual conversion module. It parses standard headings, inline parameters (bold, italic, code tags), lists, and links directly from basic Markdown source blocks, translating them cleanly into professional OOXML document trees.
How to Markdown-to-Word Conversion via Go Library?
package main
import (
"log"
"github.com/zerx-lab/wordZero/pkg/markdown"
)
func main() {
// Initialize a standard options Markdown converter block
converter := markdown.NewConverter(markdown.DefaultOptions())
// Define raw text variables highlighting structured Markdown elements
markdownContent := `
# Project Documentation
Welcome to automated generation.
## Features Included
- **High-Performance Compilation** via native Go routines.
- Clean nested element styling hooks.`
// Process raw strings directly into a formatted .docx file
err := converter.ConvertStringToFile(markdownContent, "markdown_transformed.docx")
if err != nil {
log.Fatalf("Markdown parsing pipeline encounter error: %v", err)
}
}