forked from tealeg/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlDrawingRelationship.go
33 lines (28 loc) · 1.1 KB
/
xmlDrawingRelationship.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
package xlsx
import (
"encoding/xml"
"fmt"
)
type xlsxDrawingRelationships struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/relationships Relationships"`
Relationships []*xlsxDrawingRelationship ``
}
type xlsxDrawingRelationship struct {
XMLName xml.Name `xml:"Relationship"`
Id string `xml:",attr"`
Type string `xml:",attr"`
Target string `xml:",attr"`
}
func newXlsxDrawingRelationships() *xlsxDrawingRelationships {
relationships := new(xlsxDrawingRelationships)
relationships.Relationships = make([]*xlsxDrawingRelationship, 0)
return relationships
}
func (relationships *xlsxDrawingRelationships) AddDrawingRelationship(imageName string) string {
relationship := new(xlsxDrawingRelationship)
relationship.Id = fmt.Sprintf("rId%d", len(relationships.Relationships)+1)
relationship.Type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
relationship.Target = fmt.Sprintf("../media/%s", imageName)
relationships.Relationships = append(relationships.Relationships, relationship)
return relationship.Id
}