English | δΈζ
WordZero is a Golang-based Word document manipulation library that provides basic document creation and modification operations. This library follows the latest Office Open XML (OOXML) specifications and focuses on supporting modern Word document format (.docx).
- π Complete Document Operations: Create, read, and modify Word documents
- π¨ Rich Style System: 18 predefined styles with custom style and inheritance support
- π Text Formatting: Full support for fonts, sizes, colors, bold, italic, and more
- π Paragraph Format: Alignment, spacing, indentation, and other paragraph properties
- π·οΈ Heading Navigation: Complete support for Heading1-9 styles, recognizable by Word navigation pane
- π Table Functionality: Complete table creation, editing, styling, and iterator support
- π Page Settings: Page size, margins, headers/footers, and professional layout features
- π§ Advanced Features: Table of contents generation, footnotes/endnotes, list numbering, template engine, etc.
- π― Template Inheritance: Support for base templates and block override mechanisms for template reuse and extension
- β‘ Excellent Performance: Zero-dependency pure Go implementation, average 2.62ms processing speed, 3.7x faster than JavaScript, 21x faster than Python
- π§ Easy to Use: Clean API design with fluent interface support
go get github.com/ZeroHawkeye/wordZeroWe recommend using versioned installation:
# Install latest version
go get github.com/ZeroHawkeye/wordZero@latest
# Install specific version
go get github.com/ZeroHawkeye/[email protected]package main
import (
"log"
"github.com/ZeroHawkeye/wordZero/pkg/document"
"github.com/ZeroHawkeye/wordZero/pkg/style"
)
func main() {
// Create new document
doc := document.New()
// Add title
titlePara := doc.AddParagraph("WordZero Usage Example")
titlePara.SetStyle(style.StyleHeading1)
// Add body paragraph
para := doc.AddParagraph("This is a document example created using WordZero.")
para.SetFontFamily("Arial")
para.SetFontSize(12)
para.SetColor("333333")
// Create table
tableConfig := &document.TableConfig{
Rows: 3,
Columns: 3,
}
table := doc.AddTable(tableConfig)
table.SetCellText(0, 0, "Header1")
table.SetCellText(0, 1, "Header2")
table.SetCellText(0, 2, "Header3")
// Save document
if err := doc.Save("example.docx"); err != nil {
log.Fatal(err)
}
}// Create base template
engine := document.NewTemplateEngine()
baseTemplate := `{{companyName}} Work Report
{{#block "summary"}}
Default summary content
{{/block}}
{{#block "content"}}
Default main content
{{/block}}`
engine.LoadTemplate("base_report", baseTemplate)
// Create extended template, override specific blocks
salesTemplate := `{{extends "base_report"}}
{{#block "summary"}}
Sales Performance Summary: Achieved {{achievement}}% this month
{{/block}}
{{#block "content"}}
Sales Details:
- Total Sales: {{totalSales}}
- New Customers: {{newCustomers}}
{{/block}}`
engine.LoadTemplate("sales_report", salesTemplate)
// Render template
data := document.NewTemplateData()
data.SetVariable("companyName", "WordZero Tech")
data.SetVariable("achievement", "125")
data.SetVariable("totalSales", "1,850,000")
data.SetVariable("newCustomers", "45")
doc, _ := engine.RenderTemplateToDocument("sales_report", data)
doc.Save("sales_report.docx")package main
import (
"log"
"github.com/ZeroHawkeye/wordZero/pkg/markdown"
)
func main() {
// Create Markdown converter
converter := markdown.NewConverter(markdown.DefaultOptions())
// Markdown content
markdownText := `# WordZero Markdown Conversion Example
Welcome to WordZero's **Markdown to Word** conversion feature!
## Supported Syntax
### Text Formatting
- **Bold text**
- *Italic text*
- ` + "`Inline code`" + `
### Lists
1. Ordered list item 1
2. Ordered list item 2
- Unordered list item A
- Unordered list item B
### Quotes and Code
> This is blockquote content
> Supporting multiple lines
` + "```" + `go
// Code block example
func main() {
fmt.Println("Hello, WordZero!")
}
` + "```" + `
---
Conversion complete!`
// Convert to Word document
doc, err := converter.ConvertString(markdownText, nil)
if err != nil {
log.Fatal(err)
}
// Save Word document
err = doc.Save("markdown_example.docx")
if err != nil {
log.Fatal(err)
}
// File conversion
err = converter.ConvertFile("input.md", "output.docx", nil)
if err != nil {
log.Fatal(err)
}
}Available in multiple languages:
- English: π Wiki Documentation
- δΈζ: π δΈζζζ‘£
Key Documentation:
- π Quick Start - Beginner's guide
- β‘ Feature Overview - Detailed description of all features
- π Performance Benchmarks - Cross-language performance comparison analysis
- ποΈ Project Structure - Project architecture and code organization
See example code in the examples/ directory:
examples/basic/- Basic functionality demoexamples/style_demo/- Style system demoexamples/table/- Table functionality demoexamples/formatting/- Formatting demoexamples/page_settings/- Page settings demoexamples/advanced_features/- Advanced features comprehensive demoexamples/template_demo/- Template functionality demoexamples/template_inheritance_demo/- Template inheritance feature demo β¨ Newexamples/markdown_conversion/- Markdown to Word feature demo β¨ New
Run examples:
# Run basic functionality demo
go run ./examples/basic/
# Run style demo
go run ./examples/style_demo/
# Run table demo
go run ./examples/table/
# Run template inheritance demo
go run ./examples/template_inheritance_demo/
# Run Markdown to Word demo
go run ./examples/markdown_conversion/- Document Operations: Create, read, save, parse DOCX documents
- Text Formatting: Fonts, sizes, colors, bold, italic, etc.
- Style System: 18 predefined styles + custom style support
- Paragraph Format: Alignment, spacing, indentation, complete support
- Table Functionality: Complete table operations, styling, cell iterators
- Page Settings: Page size, margins, headers/footers, etc.
- Advanced Features: Table of contents generation, footnotes/endnotes, list numbering, template engine (with template inheritance)
- Image Features: Image insertion, size adjustment, position setting
- Markdown to Word: High-quality Markdown to Word conversion based on goldmark β¨ New
- Table sorting and advanced operations
- Bookmarks and cross-references
- Document comments and revisions
- Graphics drawing functionality
- Multi-language and internationalization support
π View complete feature list: Feature Overview
WordZero excels in performance, verified through comprehensive benchmarks:
| Language | Average Execution Time | Relative Performance |
|---|---|---|
| Golang | 2.62ms | 1.00Γ |
| JavaScript | 9.63ms | 3.67Γ |
| Python | 55.98ms | 21.37Γ |
π View detailed performance analysis: Performance Benchmarks
wordZero/
βββ pkg/ # Core library code
β βββ document/ # Document operation features
β βββ style/ # Style management system
βββ examples/ # Usage examples
βββ test/ # Integration tests
βββ benchmark/ # Performance benchmarks
βββ wordZero.wiki/ # Complete documentation
π View detailed structure description: Project Structure
Issues and Pull Requests are welcome! Please ensure before submitting code:
- Code follows Go coding standards
- Add necessary test cases
- Update relevant documentation
- Ensure all tests pass
This project is licensed under the MIT License. See the LICENSE file for details.
More Resources:
- π Complete Documentation
- π§ API Reference
- π‘ Best Practices
- π Changelog