forked from gonfva/docxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (48 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
package main
import (
"flag"
"fmt"
"os"
"github.com/extrame/docx"
"github.com/golang/glog"
)
var fileLocation *string
func init() {
fileLocation = flag.String("file", "/tmp/new-file.docx", "file location")
flag.Parse()
}
func main() {
//Now let's try to read the file
readFile, err := os.Open(*fileLocation)
if err != nil {
panic(err)
}
fileinfo, err := readFile.Stat()
if err != nil {
panic(err)
}
size := fileinfo.Size()
doc, err := docx.Parse(readFile, int64(size))
if err != nil {
panic(err)
}
for _, para := range doc.Paragraphs() {
glog.Infoln("There is a new paragraph", para)
// for _, child := range para.Children() {
// if child.Run != nil && child.Run.Text != nil {
// fmt.Printf("\tWe've found a new run with the text ->%s\n", child.Run.Text.Text)
// }
// if child.Link != nil {
// id := child.Link.ID
// text := child.Link.Run.InstrText
// link, err := doc.References(id)
// if err != nil {
// fmt.Printf("\tWe found a link with id %s and text %s without target\n", id, text)
// } else {
// fmt.Printf("\tWe've found a new hyperlink with ref %s and the text %s\n", link, text)
// }
// }
// }
}
fmt.Println("End of main")
}