godocx

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 5 Imported by: 0

README

Godocx

Go Reference

Godocx is a library written in pure Go providing a set of functions that allow you to write to and read from Docx file. This library needs Go version 1.26 or later.

This library is a fork of unmaintained gomutex/godocx

Installation

go get github.com/ubavic/godocx

Example

package main

import (
	"log"

	"github.com/ubavic/godocx"
)

func main() {
	document, err := godocx.NewDocument()
	if err != nil {
		log.Fatal(err)
	}

	document.AddHeading("Document Title", 0)

	// Add a new paragraph to the document
	p := document.AddParagraph("A plain paragraph having some ")
	p.AddText("bold").Bold(true)
	p.AddText(" and some ")
	p.AddText("italic.").Italic(true)

	document.AddHeading("Heading, level 1", 1)
	document.AddParagraph("Intense quote").Style("Intense Quote")
	document.AddParagraph("first item in unordered list").Style("List Bullet")
	document.AddParagraph("first item in ordered list").Style("List Number")

	records := []struct{ Qty, ID, Desc string }{{"5", "A001", "Laptop"}, {"10", "B202", "Smartphone"}, {"2", "E505", "Smartwatch"}}

	table := document.AddTable()
	table.Style("LightList-Accent4")
	hdrRow := table.AddRow()
	hdrRow.AddCell().AddParagraph("Qty")
	hdrRow.AddCell().AddParagraph("ID")
	hdrRow.AddCell().AddParagraph("Description")

	for _, record := range records {
		row := table.AddRow()
		row.AddCell().AddParagraph(record.Qty)
		row.AddCell().AddParagraph(record.ID)
		row.AddCell().AddParagraph(record.Desc)
	}

	err = document.SaveTo("demo.docx")
	if err != nil {
		log.Fatal(err)
	}
}

Screenshot of the demo output

Licenses

The Godocx library is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDocument

func NewDocument() (*docx.RootDoc, error)

Creates a new document from the default template.

func OpenDocument deprecated

func OpenDocument(fileName string) (*docx.RootDoc, error)

Opens a document from the given file name.

Deprecated: Read file by yourself and use `ParseDocument`

func ParseDocument

func ParseDocument(doc []byte) (*docx.RootDoc, error)

Creates a new document from a valid in-memory representation.

Types

This section is empty.

Directories

Path Synopsis
common
constants
Package constants provides constant values related to OpenXML namespaces, relationships, and other attributes.
Package constants provides constant values related to OpenXML namespaces, relationships, and other attributes.
dml
Package dml provides functionality for working with DrawingML (Drawing Markup Language) which is part of the Office Open XML (OOXML) standard.
Package dml provides functionality for working with DrawingML (Drawing Markup Language) which is part of the Office Open XML (OOXML) standard.
dmlct
Package dmlct provides complex types related to DrawingML (Drawing Markup Language), which is part of the Office Open XML (OOXML) standard.
Package dmlct provides complex types related to DrawingML (Drawing Markup Language), which is part of the Office Open XML (OOXML) standard.
dmlpic
These elements encompass the definition of pictures within the DrawingML framework.
These elements encompass the definition of pictures within the DrawingML framework.
dmlst
Package dml provides simple types used in DrawingML (Drawing Markup Language), part of the Office Open XML (OOXML) standard for representing graphical elements in documents.
Package dml provides simple types used in DrawingML (Drawing Markup Language), part of the Office Open XML (OOXML) standard for representing graphical elements in documents.
Package docx provides a comprehensive set of functions and structures for manipulating DOCX documents.
Package docx provides a comprehensive set of functions and structures for manipulating DOCX documents.
Package opc provides functionality related to Open Packaging Conventions (OPC).
Package opc provides functionality related to Open Packaging Conventions (OPC).
wml
ctypes
Package ctypes provides complex types used in various components of Office Open XML (OOXML) WordprocessingML (WML) documents.
Package ctypes provides complex types used in various components of Office Open XML (OOXML) WordprocessingML (WML) documents.
stypes
Package stypes provides simple types used in Office Open XML (OOXML) WordprocessingML (WML) documents.
Package stypes provides simple types used in Office Open XML (OOXML) WordprocessingML (WML) documents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL