-
Notifications
You must be signed in to change notification settings - Fork 40
/
docxt.go
47 lines (40 loc) · 1.18 KB
/
docxt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package docxt
import (
"io"
"errors"
"github.com/qida/go-docx-templates/docx"
)
// DocxTemplateFile - файл шаблонизатора
type DocxTemplateFile struct {
file *docx.SimpleDocxFile
}
// OpenTemplate - open template
func OpenTemplate(fileName string) (*DocxTemplateFile, error) {
f, err := docx.OpenFile(fileName)
if err != nil {
return nil, err
}
return &DocxTemplateFile{file:f}, nil
}
// Save (DocxTemplateFile)
func (t *DocxTemplateFile) Save(fileName string) error {
return t.file.Save(fileName)
}
// Write (DocxTemplateFile)
func (t *DocxTemplateFile) Write(w io.Writer) error {
return t.file.Write(w)
}
// RenderTemplate (SimpleDocxFile) - рендер шаблона
func (t *DocxTemplateFile) RenderTemplate(v interface{}) error {
if t.file != nil {
return t.file.Render(v)
}
return errors.New("Not loading template file")
}
// RenderHeaderTemplate (SimpleDocxFile) - рендер шаблона
func (t *DocxTemplateFile) RenderHeaderTemplate(indexHeader int, v interface{}) error {
if t.file != nil {
return t.file.RenderHeader(indexHeader, v)
}
return errors.New("Not loading template file")
}