forked from lukasjarosch/go-docx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (43 loc) · 1.2 KB
/
main.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
48
49
50
51
52
53
54
55
package main
import (
"flag"
"log"
"time"
"github.com/sonnt0309/go-docx"
)
var templatePath, outputPath string
func init() {
flag.StringVar(&templatePath, "template", "template.docx", "path to the template docx file")
flag.StringVar(&outputPath, "out", "replaced.docx", "path to the output docx")
}
func main() {
startTime := time.Now()
flag.Parse()
replaceMap := docx.PlaceholderMap{
"key": "REPLACE some more",
"key-with-dash": "REPLACE",
"key-with-dashes": "REPLACE",
"key with space": "REPLACE",
"key_with_underscore": "REPLACE",
"multiline": "REPLACE",
"key.with.dots": "REPLACE",
"mixed-key.separator_styles#": "REPLACE",
"yet-another_placeholder": "REPLACE",
"foo": "bar",
}
doc, err := docx.Open(templatePath)
if err != nil {
log.Fatal(err)
}
log.Printf("open took: %s", time.Since(startTime))
err = doc.ReplaceAll(replaceMap)
if err != nil {
panic(err)
}
log.Printf("replace took: %s", time.Since(startTime))
err = doc.WriteToFile(outputPath)
if err != nil {
panic(err)
}
log.Printf("everything took: %s", time.Since(startTime))
}