docx

package module
v0.0.0-...-0b0ebf4 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 5 Imported by: 0

README

docx

GitHub release (latest SemVer) Go Report Card GoDoc

Introduction

docx is a simple library to creating DOCX file in Go.

Getting Started

Install

Go modules supported

go get github.com/danvergara/docx

Import:

import "github.com/danvergara/docx"
Usage

Example:

package main

import (
	"github.com/danvergara/docx"
)

func main() {
	f := docx.NewFile()
	// add new paragraph
	para := f.AddParagraph()
	// add text
	para.AddText("test")

	para.AddText("test font size").Size(22)
	para.AddText("test color").Color("808080")
	para.AddText("test font size and color").Size(22).Color("121212")

	nextPara := f.AddParagraph()
	nextPara.AddLink("google", `http://google.com`)

	f.Save("./test.docx")
}

Documentation

Index

Constants

View Source
const (
	XMLNS_W = `http://schemas.openxmlformats.org/wordprocessingml/2006/main`
	XMLNS_R = `http://schemas.openxmlformats.org/officeDocument/2006/relationships`
)
View Source
const (
	XMLNS         = `http://schemas.openxmlformats.org/package/2006/relationships`
	REL_HYPERLINK = `http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink`

	REL_TARGETMODE = "External"
)
View Source
const (
	TEMP_REL = `` /* 601-byte string literal not displayed */

	TEMP_DOCPROPS_APP  = `` /* 276-byte string literal not displayed */
	TEMP_DOCPROPS_CORE = `` /* 363-byte string literal not displayed */
	TEMP_CONTENT       = `` /* 934-byte string literal not displayed */

	TEMP_WORD_STYLE = `` /* 1743-byte string literal not displayed */

	TEMP_WORD_THEME_THEME = `` /* 9767-byte string literal not displayed */

)
View Source
const (
	HYPERLINK_STYLE = "a1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body struct {
	XMLName   xml.Name `xml:"w:body"`
	Paragraph []*Paragraph
}

type Color

type Color struct {
	XMLName xml.Name `xml:"w:color"`
	Val     string   `xml:"w:val,attr"`
}

type DocRelation

type DocRelation struct {
	XMLName      xml.Name        `xml:"Relationships"`
	Xmlns        string          `xml:"xmlns,attr"`
	Relationship []*RelationShip `xml:"Relationship"`
}

type Document

type Document struct {
	XMLName xml.Name `xml:"w:document"`
	XMLW    string   `xml:"xmlns:w,attr"`
	XMLR    string   `xml:"xmlns:r,attr"`
	Body    *Body
}

type File

type File struct {
	Document    Document
	DocRelation DocRelation
	// contains filtered or unexported fields
}

func NewFile

func NewFile() *File

func (*File) AddParagraph

func (f *File) AddParagraph() *Paragraph

AddParagraph add new paragraph

func (*File) Save

func (f *File) Save(path string) (err error)

Save save file to path

func (*File) Write

func (f *File) Write(writer io.Writer) (err error)
type Hyperlink struct {
	XMLName xml.Name `xml:"w:hyperlink"`
	ID      string   `xml:"r:id,attr"`
	Run     Run
}

type Paragraph

type Paragraph struct {
	XMLName xml.Name `xml:"w:p"`
	Data    []interface{}
	// contains filtered or unexported fields
}
func (p *Paragraph) AddLink(text string, link string) *Hyperlink

AddLink add hyperlink to paragraph

func (*Paragraph) AddText

func (p *Paragraph) AddText(text string) *Run

AddText add text to paragraph

type RelationShip

type RelationShip struct {
	XMLName    xml.Name `xml:"Relationship"`
	ID         string   `xml:"Id,attr"`
	Type       string   `xml:"Type,attr"`
	Target     string   `xml:"Target,attr"`
	TargetMode string   `xml:"TargetMode,attr,omitempty"`
}

type Run

type Run struct {
	XMLName       xml.Name       `xml:"w:r"`
	RunProperties *RunProperties `xml:"w:rPr,omitempty"`
	InstrText     string         `xml:"w:instrText,omitempty"`
	Text          *Text
}

func (*Run) Color

func (r *Run) Color(color string) *Run

Color set run color

func (*Run) Size

func (r *Run) Size(size int) *Run

Size set run size

type RunProperties

type RunProperties struct {
	XMLName  xml.Name  `xml:"w:rPr"`
	Color    *Color    `xml:"w:color,omitempty"`
	Size     *Size     `xml:"w:sz,omitempty"`
	RunStyle *RunStyle `xml:"w:rStyle,omitempty"`
}

type RunStyle

type RunStyle struct {
	XMLName xml.Name `xml:"w:rStyle"`
	Val     string   `xml:"w:val,attr"`
}

type Size

type Size struct {
	XMLName xml.Name `xml:"w:sz"`
	Val     int      `xml:"w:val,attr"`
}

type Text

type Text struct {
	XMLName  xml.Name `xml:"w:t"`
	XMLSpace string   `xml:"xml:space,attr,omitempty"`
	Text     string   `xml:",chardata"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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