-
Notifications
You must be signed in to change notification settings - Fork 9
/
apilink.go
39 lines (31 loc) · 829 Bytes
/
apilink.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
package docxlib
import "strconv"
// when adding an hyperlink we need to store a reference in the relationship field
func (f *DocxLib) addLinkRelation(link string) string {
rel := &Relationship{
ID: "rId" + strconv.Itoa(f.rId),
Type: REL_HYPERLINK,
Target: link,
TargetMode: REL_TARGETMODE,
}
f.rId += 1
f.DocRelation.Relationships = append(f.DocRelation.Relationships, rel)
return rel.ID
}
// AddLink adds an hyperlink to paragraph
func (p *Paragraph) AddLink(text string, link string) *Hyperlink {
rId := p.file.addLinkRelation(link)
hyperlink := &Hyperlink{
ID: rId,
Run: Run{
RunProperties: &RunProperties{
RunStyle: &RunStyle{
Val: HYPERLINK_STYLE,
},
},
InstrText: text,
},
}
p.Data = append(p.Data, ParagraphChild{Link: hyperlink})
return hyperlink
}