Skip to content

Golang package to generate document based on docx template

License

Notifications You must be signed in to change notification settings

habibridho/cetak

Repository files navigation

Cetak

GoDoc Build Status Coverage Status

Golang package that helps you generate Word document (.docx) from a template. It utilises go's text/template package behind the scene so you can use the same annotation in your template.

Usage

To use this package, simply create new Docx object and call Generate with your data dan destination path.

...
d, err := cetak.New("/path/to/template.docx")
if err != nil {
    // handle error
}

type TemplateData struct {
    Title   string
	Content string
}

data := TemplateData{
    Title:   "This is The Title",
    Content: "Hello World!",
}

err = d.Generate(data, "/path/to/result.docx")
if err != nil {
    // handle error
}
...

In the above sample, we assume to have a template ready in /path/to/template.docx. We will inject data which has an arbitrary TemplateData type. Note that the data type can be anything where the fields correspond to annotations inside the template. In this sample, template.docx has {{.Title}} and {{.Content}} inside of it. The result will be stored in the given result path, ie /path/to/result.docx.

License

This package is licensed under MIT License.

About

Golang package to generate document based on docx template

Resources

License

Stars

Watchers

Forks

Packages

No packages published