mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-10 10:23:19 +08:00
First commit
This commit is contained in:
38
link.go
Normal file
38
link.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package docxlib
|
||||
|
||||
import "strconv"
|
||||
|
||||
func (f *Docx) 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 add 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
|
||||
}
|
||||
Reference in New Issue
Block a user