Skip to content

Golang library for modify Microsoft Word (.Docx) files

License

Notifications You must be signed in to change notification settings

PedroReboli/SuperGoDocx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Super Go Docx

Golang library for modify Microsoft Word (.Docx) files

Install

go get github.com/PedroReboli/SuperGoDocx/SuperDocx

Example code

import docx "github.com/PedroReboli/SuperGoDocx/SuperDocx"
func main() {
	//Open file
	doc,err := docx.Open("./Example.docx")
	if err != nil {
		panic(err)
	}
	//Create and append paragraph
	para := doc.Document.Body.CreateAddParagraph()
	//Create and append run in paragraph
	run := para.CreateRun()
	//set style bold
	run.Style.SetBold(true)
	//set text of run
	run.SetText("Hello World")
	para1 := doc.Document.Body.CreateAddParagraph()
	para1.CreateRuns(2)
	//size is in half-points (half-poits = fontsize*2)
	para1.Runs[0].Style.SetSize(20)
	para1.Runs[0].Style.SetItalic(true)
	para1.Runs[0].SetText("run0 ")
	para1.Runs[1].Style.SetSize(21)
	para1.Runs[1].SetText("run1 ")
	para1.Runs[2].Style.SetSize(21)
	para1.Runs[2].Style.SetCaps(true)
	para1.Runs[2].SetText("run2")
	//replace text even if it is across runs. new text using same style of the fist old text letter
	para1.Replace("run0 run1 ru", "new text to replace old with italic style")
	err = doc.SaveAs("./NewDocument.docx")
	// or ([]byte ,error) doc.SaveToMemory()
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Credits

using a slightly modified version of go-xmldom

thanks to @DesenhaMenina to draw this amazing gopher

About

Golang library for modify Microsoft Word (.Docx) files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages