https://github.com/didikprabowo/mbadocx
Go library for programmatically creating and manipulating Microsoft Word (DOCX) documents
https://github.com/didikprabowo/mbadocx
document docx golang golang-library openoffice word xml
Last synced: 6 months ago
JSON representation
Go library for programmatically creating and manipulating Microsoft Word (DOCX) documents
- Host: GitHub
- URL: https://github.com/didikprabowo/mbadocx
- Owner: didikprabowo
- License: mit
- Created: 2025-08-03T05:48:33.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-22T19:35:47.000Z (10 months ago)
- Last Synced: 2025-08-22T21:14:20.507Z (10 months ago)
- Topics: document, docx, golang, golang-library, openoffice, word, xml
- Language: Go
- Homepage:
- Size: 139 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
**Go library for creating, reading and manipulating DOCX files**

[](https://pkg.go.dev/github.com/didikprabowo/mbadocx)
[](https://goreportcard.com/report/github.com/didikprabowo/mbadocx)
[](https://opensource.org/licenses/MIT)
## Overview
**Mbadocx** is a Go library for programmatically creating and manipulating Microsoft Word (DOCX) documents.
It provides a modular, extensible API for generating Word documents with advanced formatting, metadata, and resource management.
### Key Features
- ✅ **Document Creation** - Create new DOCX documents from scratch
- ✅ **Text Formatting** - Bold, italic, colors, font sizes
- ✅ **Paragraphs** - Full paragraph management and styling
- ✅ **Tables** - Create and format tables with rows and cells
- ✅ **Image** - Add image and set properties
- ✅ **Hyperlinks** - Add clickable links to documents
- ✅ **Line Breaks** - Control document flow
- ✅ **Fluent API** - Chainable methods for clean code
- ✅ **Pure Go** - No external dependencies required
### Examples
- [Basic Document](./example/basic)
- [List Numbering](./example/list)
- [Text Formating](./example/text-formatting)
- [Tables](./example/table)
- [Image](./example/image)
### Why mbadocx?
- Idiomatic Go - Follows Go best practices and conventions
- Lightweight - Minimal overhead and dependencies
- Extensible - Modular architecture for easy extension
- MIT Licensed - Use freely in commercial and open-source projects
## Installation
### Requirements
- Go 1.16 or higher
- No external dependencies required
### Install via go get
```bash
go get github.com/didikprabowo/mbadocx
```
### Import in your code
```go
import "github.com/didikprabowo/mbadocx"
```
## Quick Start
Here's a simple example to get you started:
```go
package main
import (
"log"
"github.com/didikprabowo/mbadocx"
)
func main() {
// Create a new document
doc := mbadocx.New()
// Add a paragraph with formatted text
para := doc.AddParagraph()
para.AddText("Hello, World!").SetBold(true).SetFontSize(16)
// Save the document
if err := doc.Save("hello.docx"); err != nil {
log.Fatal(err)
}
}
```
### Creating Tables
```go
package main
import (
"log"
"github.com/didikprabowo/mbadocx"
"github.com/didikprabowo/mbadocx/elements"
)
func main() {
doc := mbadocx.New()
// Add title
doc.AddHeading("Table Examples in mbadocx", 1)
doc.AddParagraph().AddText("This document demonstrates various table features.")
// Example 1: Simple table
doc.AddHeading("Example 1: Basic Table", 2)
doc.AddParagraph().AddText("A simple 3x3 table:")
table1 := doc.AddTable(3, 3)
if table1 != nil {
// Add headers
table1.SetCellFormattedText(0, 0, "Name", func(r *elements.Run) {
r.SetSpacing(2)
r.SetBold(true)
})
table1.SetCellFormattedText(0, 1, "Age", func(r *elements.Run) {
r.SetBold(true)
})
table1.SetCellFormattedText(0, 2, "City", func(r *elements.Run) {
r.SetBold(true)
})
// Add data
table1.SetCellText(1, 0, "John Doe")
table1.SetCellText(1, 1, "30")
table1.SetCellText(1, 2, "New York")
table1.SetCellText(2, 0, "Jane Smith")
table1.SetCellText(2, 1, "25")
table1.SetCellText(2, 2, "London")
// Set table properties
table1.SetTableAlignment("center")
}
// Save the document
if err := doc.Save("testdata/table_examples.docx"); err != nil {
log.Fatalf("Failed to save document: %v", err)
}
}
```
### Adding Images
```go
package main
import (
"log"
"github.com/didikprabowo/mbadocx"
"github.com/didikprabowo/mbadocx/properties"
)
func main() {
docx := mbadocx.New()
docx.AddParagraph().AddText("Image with Borders and Effects")
img1, err := docx.AddImage("mbadocx_logo.png")
if err != nil {
log.Fatal("failed add image")
}
img1.
SetBorder(3, "#FF0000").
SetAlignment(properties.AlignCenter)
if err := docx.Save("testdata/image.docx"); err != nil {
log.Fatalf("Failed to save document: %v", err)
}
}
```
## Contributing
Contributions are welcome!
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
---
## License
MIT License. See [LICENSE](./LICENSE) for details.