Skip to content

GoWordIndustrial Word (.docx) Engine

100% pure Go standard library, zero third-party dependencies — an industrial-grade engine for Microsoft Word (.docx) processing.

Go ReferenceCILicense: LGPL v3Go 1.21+v0.11.0

Current development APIs ​

The reader now restores section geometry and common header/footer parts, notes, comments, revisions, and list numbering. Template replacement handles macros split across adjacent Word text runs. NewWithOptions provides isolated document defaults, and ValidatePackage reports package diagnostics. See Reader & Diagnostics.

What's new in v0.11.0 ​

  • Set optional ZIP budgets with ReadOptions and the WithOptions APIs. Existing APIs retain unlimited reads. See limits and a runnable example.
  • Fix output error propagation, repeated-save comments, header/footer relationships, template image XML and delimiter isolation, and text/bookmark preservation during reading and merging.
  • Reduce XML input copying and cache resource relationship lookups.

See the v0.11.0 release and changelog.

Core advantages ​

Production Word pipelines usually stall on four constraints: shipping a binary into an air-gapped network, keeping RAM flat on multi-hundred-page extracts, emitting equations Microsoft Word can edit, and filling legal templates without a second templating stack.

ConstraintGoWordTypical PHP / Python stackOther Go .docx writers
Language & depsGo 1.21+ standard library onlyruntime + XML / ZIP extrasoften stdlib, write-only surface
Extract memoryStreamExtractText O(1) extra heapload the whole package / DOMfull document tree
EquationsLaTeX → native OMML (m:oMathPara)image, OLE, or omitomit
Templates${var | pipe} + ${block} / ${if}PHPWord macros or Jinja→docxomit or string replace
Merge isolationAppendDocument remaps styles, bookmarks, rIdZIP copy, colliding image1.pngomit
LicenseLGPL v3mixedAGPL or MIT write-only

GoWord keeps the PHPWord names (AddSection, AddText, IOFactory, TemplateProcessor) on a pure-Go OpenXML writer. Four copy-paste programs that combine these advantages live under Enterprise Recipes.

Benchmarks ​

Numbers from go test -benchmem on Intel Core i7-10870H, Windows amd64. Allocations are the stable signal; wall time moves with disk and CPU. Full tables, hardware notes, and a streaming-extract occupancy example: Benchmarks.

Workloadns/opB/opallocs/op
BenchmarkSaveDocx — 30 paragraphs + 20×5 table1.88e6163 KiB949
BenchmarkTableRender — 50×8 table2.76e6180 KiB1820
BenchmarkTemplateProcess — two ${} replacements1.43e6238 KiB703
BenchmarkStreamWriter — incremental ZIP1.55e6142 KiB627

B/op is extra heap per iteration, not the size of the .docx. Stream extract discards each paragraph buffer after the callback, so extra memory stays O(1) relative to file size.

Feature comparison ​

GoWord ports the PHPWord public API (AddSection, AddText, IOFactory, TemplateProcessor) onto a pure-Go OpenXML writer. The table below compares the surface that production Word pipelines usually need.

CapabilityGoWordPHPWorduniofficefumiama/go-docxgingfrederik/docx
LanguageGo 1.21+PHPGo (commercial)GoGo
LicenseLGPL v3LGPL v3CommercialAGPL-3.0MIT
Third-party Go depsNonen/aNone (paid SDK)NoneNone
Create .docx✓✓✓✓✓
Read / round-trip .docx✓✓✓✓
Native OMML from LaTeX✓✓
DrawingML charts (bar / line / pie / area / combo)✓✓✓
Vector shapes wps:wsp✓✓✓✓
Multi-column w:cols✓✓✓
Nested tables + vMerge / gridSpan✓✓✓✓
Repeating tblHeader / cantSplit / textDirection✓✓✓
SDT content controls (w:sdt)✓✓✓
Template ${var | pipe} + ${block} / ${if}✓✓templates
O(1) stream extract✓
Merge with style / bookmark / rId isolation✓✓
Tiled / image watermark + w:permStart exceptions✓✓✓

PHPWord is the API ancestor. unioffice is a paid, multi-format Office SDK. The two lightweight Go writers cover paragraphs (and, for go-docx, pictures and tables) and stop short of OMML, charts, streaming extract, and identifier-safe merge.

Quick start ​

go
package main

import (
	"log"

	"github.com/yunkeweb/go-word"
)

func main() {
	doc := word.New()
	doc.SetDefaultFontName("Calibri")
	sec := doc.AddSection()
	sec.AddTitle("GoWord v0.11.0", 1)
	sec.AddSDTText("Full name", "full_name", "Enter full name")
	sec.AddMath(`\frac{a}{b}`)
	doc.SetTextWatermark("CONFIDENTIAL", word.WatermarkOptions{Tile: true, Angle: -45})
	if err := doc.Save("hello.docx"); err != nil {
		log.Fatal(err)
	}
}
sh
go get github.com/yunkeweb/go-word@v0.11.0

Continue with Installation, Quick Start, SDT, Tables, Watermark & Protection, and the four Enterprise Recipes. Full signatures live on pkg.go.dev.

Released under the GNU LGPL v3.0.