2017-01-17 19:06:42 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-02-28 12:59:04 +08:00
|
|
|
"encoding/json"
|
2017-01-17 19:06:42 +08:00
|
|
|
"encoding/xml"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2017-01-22 16:16:03 +08:00
|
|
|
"image"
|
2017-01-17 19:06:42 +08:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-02-28 12:59:04 +08:00
|
|
|
// parseFormatPictureSet provides function to parse the format settings of the
|
|
|
|
// picture with default value.
|
|
|
|
func parseFormatPictureSet(formatSet string) *xlsxFormatPicture {
|
|
|
|
format := xlsxFormatPicture{
|
|
|
|
FPrintsWithSheet: true,
|
|
|
|
FLocksWithSheet: false,
|
|
|
|
NoChangeAspect: false,
|
|
|
|
OffsetX: 0,
|
|
|
|
OffsetY: 0,
|
|
|
|
XScale: 1.0,
|
|
|
|
YScale: 1.0,
|
|
|
|
}
|
|
|
|
json.Unmarshal([]byte(formatSet), &format)
|
|
|
|
return &format
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddPicture provides the method to add picture in a sheet by given picture
|
|
|
|
// format set (such as offset, scale, aspect ratio setting and print settings)
|
|
|
|
// and file path. For example:
|
2017-01-17 19:06:42 +08:00
|
|
|
//
|
2017-01-22 19:20:33 +08:00
|
|
|
// package main
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2017-01-22 19:20:33 +08:00
|
|
|
// import (
|
|
|
|
// "fmt"
|
|
|
|
// "os"
|
|
|
|
// _ "image/gif"
|
|
|
|
// _ "image/jpeg"
|
|
|
|
// _ "image/png"
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2017-01-22 19:20:33 +08:00
|
|
|
// "github.com/Luxurioust/excelize"
|
|
|
|
// )
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2017-01-22 19:20:33 +08:00
|
|
|
// func main() {
|
2017-01-22 16:16:03 +08:00
|
|
|
// xlsx := excelize.CreateFile()
|
|
|
|
// // Insert a picture.
|
2017-02-28 12:59:04 +08:00
|
|
|
// err := xlsx.AddPicture("Sheet1", "A2", "/tmp/image1.jpg", "")
|
2017-02-12 19:03:24 +08:00
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
2017-01-22 16:16:03 +08:00
|
|
|
// // Insert a picture to sheet with scaling.
|
2017-02-28 12:59:04 +08:00
|
|
|
// err = xlsx.AddPicture("Sheet1", "D2", "/tmp/image1.png", `{"x_scale": 0.5, "y_scale": 0.5}`)
|
2017-02-12 19:03:24 +08:00
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
2017-02-28 12:59:04 +08:00
|
|
|
// // Insert a picture offset in the cell with printing support.
|
|
|
|
// err = xlsx.AddPicture("Sheet1", "H2", "/tmp/image3.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
|
2017-01-22 16:16:03 +08:00
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// err = xlsx.WriteTo("/tmp/Workbook.xlsx")
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
2017-01-17 19:06:42 +08:00
|
|
|
// }
|
|
|
|
//
|
2017-02-28 12:59:04 +08:00
|
|
|
func (f *File) AddPicture(sheet, cell, picture, format string) error {
|
2017-01-22 16:16:03 +08:00
|
|
|
var supportTypes = map[string]string{".gif": ".gif", ".jpg": ".jpeg", ".jpeg": ".jpeg", ".png": ".png"}
|
2017-01-17 19:06:42 +08:00
|
|
|
var err error
|
|
|
|
// Check picture exists first.
|
|
|
|
if _, err = os.Stat(picture); os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ext, ok := supportTypes[path.Ext(picture)]
|
|
|
|
if !ok {
|
|
|
|
return errors.New("Unsupported image extension")
|
|
|
|
}
|
2017-01-22 16:16:03 +08:00
|
|
|
readFile, _ := os.Open(picture)
|
|
|
|
image, _, err := image.DecodeConfig(readFile)
|
2017-01-17 19:06:42 +08:00
|
|
|
_, file := filepath.Split(picture)
|
2017-02-28 12:59:04 +08:00
|
|
|
formatSet := parseFormatPictureSet(format)
|
2017-01-17 19:06:42 +08:00
|
|
|
// Read sheet data.
|
|
|
|
var xlsx xlsxWorksheet
|
|
|
|
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
|
|
|
|
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
|
|
|
|
// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
|
|
|
|
drawingID := f.countDrawings() + 1
|
|
|
|
pictureID := f.countMedia() + 1
|
|
|
|
drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
|
|
|
|
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
|
|
|
|
|
|
|
|
var drawingRID int
|
|
|
|
if xlsx.Drawing != nil {
|
|
|
|
// The worksheet already has a picture or chart relationships, use the relationships drawing ../drawings/drawing%d.xml.
|
|
|
|
sheetRelationshipsDrawingXML = f.getSheetRelationshipsTargetByID(sheet, xlsx.Drawing.RID)
|
|
|
|
drawingID, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(sheetRelationshipsDrawingXML, "../drawings/drawing"), ".xml"))
|
|
|
|
drawingXML = strings.Replace(sheetRelationshipsDrawingXML, "..", "xl", -1)
|
|
|
|
} else {
|
|
|
|
// Add first picture for given sheet.
|
2017-01-19 14:05:32 +08:00
|
|
|
rID := f.addSheetRelationships(sheet, SourceRelationshipDrawingML, sheetRelationshipsDrawingXML, "")
|
2017-01-17 19:06:42 +08:00
|
|
|
f.addSheetDrawing(sheet, rID)
|
|
|
|
}
|
|
|
|
drawingRID = f.addDrawingRelationships(drawingID, SourceRelationshipImage, "../media/image"+strconv.Itoa(pictureID)+ext)
|
2017-02-28 12:59:04 +08:00
|
|
|
f.addDrawing(sheet, drawingXML, cell, file, image.Width, image.Height, drawingRID, formatSet)
|
2017-01-17 19:06:42 +08:00
|
|
|
f.addMedia(picture, ext)
|
|
|
|
f.addDrawingContentTypePart(drawingID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// addSheetRelationships provides function to add
|
|
|
|
// xl/worksheets/_rels/sheet%d.xml.rels by given sheet name, relationship type
|
|
|
|
// and target.
|
2017-01-19 14:05:32 +08:00
|
|
|
func (f *File) addSheetRelationships(sheet, relType, target, targetMode string) int {
|
2017-01-17 19:06:42 +08:00
|
|
|
var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
|
|
|
|
var sheetRels xlsxWorkbookRels
|
|
|
|
var rID = 1
|
|
|
|
var ID bytes.Buffer
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
_, ok := f.XLSX[rels]
|
|
|
|
if ok {
|
|
|
|
ID.Reset()
|
|
|
|
xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
|
|
|
|
rID = len(sheetRels.Relationships) + 1
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
}
|
|
|
|
sheetRels.Relationships = append(sheetRels.Relationships, xlsxWorkbookRelation{
|
2017-01-19 14:05:32 +08:00
|
|
|
ID: ID.String(),
|
|
|
|
Type: relType,
|
|
|
|
Target: target,
|
|
|
|
TargetMode: targetMode,
|
2017-01-17 19:06:42 +08:00
|
|
|
})
|
|
|
|
output, err := xml.Marshal(sheetRels)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
f.saveFileList(rels, string(output))
|
|
|
|
return rID
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// addSheetDrawing provides function to add drawing element to
|
|
|
|
// xl/worksheets/sheet%d.xml by given sheet name and relationship index.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) addSheetDrawing(sheet string, rID int) {
|
|
|
|
var xlsx xlsxWorksheet
|
|
|
|
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
|
|
|
|
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
|
|
|
|
xlsx.Drawing = &xlsxDrawing{
|
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
|
|
|
output, err := xml.Marshal(xlsx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-01-24 18:29:02 +08:00
|
|
|
f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpace(string(output)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// addSheetPicture provides function to add picture element to
|
|
|
|
// xl/worksheets/sheet%d.xml by given sheet name and relationship index.
|
|
|
|
func (f *File) addSheetPicture(sheet string, rID int) {
|
|
|
|
var xlsx xlsxWorksheet
|
|
|
|
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
|
|
|
|
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)
|
|
|
|
xlsx.Picture = &xlsxPicture{
|
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
|
|
|
output, err := xml.Marshal(xlsx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpace(string(output)))
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// countDrawings provides function to get drawing files count storage in the
|
|
|
|
// folder xl/drawings.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) countDrawings() int {
|
|
|
|
count := 0
|
|
|
|
for k := range f.XLSX {
|
|
|
|
if strings.Contains(k, "xl/drawings/drawing") {
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// addDrawing provides function to add picture by given drawingXML, xAxis,
|
|
|
|
// yAxis, file name and relationship index. In order to solve the problem that
|
|
|
|
// the label structure is changed after serialization and deserialization, two
|
|
|
|
// different structures: decodeWsDr and encodeWsDr are defined.
|
2017-02-28 12:59:04 +08:00
|
|
|
func (f *File) addDrawing(sheet, drawingXML, cell, file string, width, height, rID int, formatSet *xlsxFormatPicture) {
|
2017-01-22 16:16:03 +08:00
|
|
|
cell = strings.ToUpper(cell)
|
|
|
|
fromCol := string(strings.Map(letterOnlyMapF, cell))
|
|
|
|
fromRow, _ := strconv.Atoi(strings.Map(intOnlyMapF, cell))
|
|
|
|
row := fromRow - 1
|
|
|
|
col := titleToNumber(fromCol)
|
2017-02-28 12:59:04 +08:00
|
|
|
width = int(float64(width) * formatSet.XScale)
|
|
|
|
height = int(float64(height) * formatSet.YScale)
|
|
|
|
colStart, rowStart, _, _, colEnd, rowEnd, x2, y2 := f.positionObjectPixels(sheet, col, row, formatSet.OffsetX, formatSet.OffsetY, width, height)
|
2017-01-17 19:06:42 +08:00
|
|
|
content := encodeWsDr{}
|
|
|
|
content.WsDr.A = NameSpaceDrawingML
|
|
|
|
content.WsDr.Xdr = NameSpaceSpreadSheetDrawing
|
|
|
|
cNvPrID := 1
|
|
|
|
_, ok := f.XLSX[drawingXML]
|
|
|
|
if ok { // Append Model
|
|
|
|
decodeWsDr := decodeWsDr{}
|
|
|
|
xml.Unmarshal([]byte(f.readXML(drawingXML)), &decodeWsDr)
|
|
|
|
cNvPrID = len(decodeWsDr.TwoCellAnchor) + 1
|
2017-03-01 11:00:42 +08:00
|
|
|
for _, v := range decodeWsDr.OneCellAnchor {
|
|
|
|
content.WsDr.OneCellAnchor = append(content.WsDr.OneCellAnchor, &xlsxCellAnchor{
|
|
|
|
EditAs: v.EditAs,
|
|
|
|
GraphicFrame: v.Content,
|
|
|
|
})
|
|
|
|
}
|
2017-01-17 19:06:42 +08:00
|
|
|
for _, v := range decodeWsDr.TwoCellAnchor {
|
2017-03-01 11:00:42 +08:00
|
|
|
content.WsDr.TwoCellAnchor = append(content.WsDr.TwoCellAnchor, &xlsxCellAnchor{
|
2017-01-17 19:06:42 +08:00
|
|
|
EditAs: v.EditAs,
|
|
|
|
GraphicFrame: v.Content,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-03-01 11:00:42 +08:00
|
|
|
twoCellAnchor := xlsxCellAnchor{}
|
2017-01-17 19:06:42 +08:00
|
|
|
twoCellAnchor.EditAs = "oneCell"
|
|
|
|
from := xlsxFrom{}
|
2017-01-22 16:16:03 +08:00
|
|
|
from.Col = colStart
|
2017-02-28 12:59:04 +08:00
|
|
|
from.ColOff = formatSet.OffsetX * EMU
|
2017-01-22 16:16:03 +08:00
|
|
|
from.Row = rowStart
|
2017-02-28 12:59:04 +08:00
|
|
|
from.RowOff = formatSet.OffsetY * EMU
|
2017-01-17 19:06:42 +08:00
|
|
|
to := xlsxTo{}
|
2017-01-22 16:16:03 +08:00
|
|
|
to.Col = colEnd
|
|
|
|
to.ColOff = x2 * EMU
|
|
|
|
to.Row = rowEnd
|
|
|
|
to.RowOff = y2 * EMU
|
2017-01-17 19:06:42 +08:00
|
|
|
twoCellAnchor.From = &from
|
|
|
|
twoCellAnchor.To = &to
|
|
|
|
pic := xlsxPic{}
|
2017-02-28 12:59:04 +08:00
|
|
|
pic.NvPicPr.CNvPicPr.PicLocks.NoChangeAspect = formatSet.NoChangeAspect
|
2017-01-17 19:06:42 +08:00
|
|
|
pic.NvPicPr.CNvPr.ID = cNvPrID
|
|
|
|
pic.NvPicPr.CNvPr.Descr = file
|
|
|
|
pic.NvPicPr.CNvPr.Name = "Picture " + strconv.Itoa(cNvPrID)
|
|
|
|
pic.BlipFill.Blip.R = SourceRelationship
|
|
|
|
pic.BlipFill.Blip.Embed = "rId" + strconv.Itoa(rID)
|
|
|
|
pic.SpPr.PrstGeom.Prst = "rect"
|
|
|
|
|
|
|
|
twoCellAnchor.Pic = &pic
|
|
|
|
twoCellAnchor.ClientData = &xlsxClientData{
|
2017-02-28 12:59:04 +08:00
|
|
|
FLocksWithSheet: formatSet.FLocksWithSheet,
|
|
|
|
FPrintsWithSheet: formatSet.FPrintsWithSheet,
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
content.WsDr.TwoCellAnchor = append(content.WsDr.TwoCellAnchor, &twoCellAnchor)
|
|
|
|
output, err := xml.Marshal(content)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
// Create replacer with pairs as arguments and replace all pairs.
|
|
|
|
r := strings.NewReplacer("<encodeWsDr>", "", "</encodeWsDr>", "")
|
|
|
|
result := r.Replace(string(output))
|
|
|
|
f.saveFileList(drawingXML, result)
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// addDrawingRelationships provides function to add image part relationships in
|
|
|
|
// the file xl/drawings/_rels/drawing%d.xml.rels by given drawing index,
|
|
|
|
// relationship type and target.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) addDrawingRelationships(index int, relType string, target string) int {
|
|
|
|
var rels = "xl/drawings/_rels/drawing" + strconv.Itoa(index) + ".xml.rels"
|
|
|
|
var drawingRels xlsxWorkbookRels
|
|
|
|
var rID = 1
|
|
|
|
var ID bytes.Buffer
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
_, ok := f.XLSX[rels]
|
|
|
|
if ok {
|
|
|
|
ID.Reset()
|
|
|
|
xml.Unmarshal([]byte(f.readXML(rels)), &drawingRels)
|
|
|
|
rID = len(drawingRels.Relationships) + 1
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
}
|
|
|
|
drawingRels.Relationships = append(drawingRels.Relationships, xlsxWorkbookRelation{
|
|
|
|
ID: ID.String(),
|
|
|
|
Type: relType,
|
|
|
|
Target: target,
|
|
|
|
})
|
|
|
|
output, err := xml.Marshal(drawingRels)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
f.saveFileList(rels, string(output))
|
|
|
|
return rID
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// countMedia provides function to get media files count storage in the folder
|
|
|
|
// xl/media/image.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) countMedia() int {
|
|
|
|
count := 0
|
|
|
|
for k := range f.XLSX {
|
|
|
|
if strings.Contains(k, "xl/media/image") {
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// addMedia provides function to add picture into folder xl/media/image by given
|
|
|
|
// file name and extension name.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) addMedia(file string, ext string) {
|
|
|
|
count := f.countMedia()
|
|
|
|
dat, _ := ioutil.ReadFile(file)
|
|
|
|
media := "xl/media/image" + strconv.Itoa(count+1) + ext
|
|
|
|
f.XLSX[media] = string(dat)
|
|
|
|
}
|
|
|
|
|
2017-02-28 12:59:04 +08:00
|
|
|
// setContentTypePartImageExtensions provides function to set the content type
|
|
|
|
// for relationship parts and the Main Document part.
|
2017-01-24 18:29:02 +08:00
|
|
|
func (f *File) setContentTypePartImageExtensions() {
|
2017-01-22 16:16:03 +08:00
|
|
|
var imageTypes = map[string]bool{"jpeg": false, "png": false, "gif": false}
|
2017-01-17 19:06:42 +08:00
|
|
|
var content xlsxTypes
|
2017-01-24 18:29:02 +08:00
|
|
|
xml.Unmarshal([]byte(f.readXML("[Content_Types].xml")), &content)
|
2017-01-17 19:06:42 +08:00
|
|
|
for _, v := range content.Defaults {
|
|
|
|
_, ok := imageTypes[v.Extension]
|
|
|
|
if ok {
|
|
|
|
imageTypes[v.Extension] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range imageTypes {
|
|
|
|
if !v {
|
|
|
|
content.Defaults = append(content.Defaults, xlsxDefault{
|
|
|
|
Extension: k,
|
|
|
|
ContentType: "image/" + k,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 18:29:02 +08:00
|
|
|
output, _ := xml.Marshal(content)
|
|
|
|
f.saveFileList("[Content_Types].xml", string(output))
|
|
|
|
}
|
|
|
|
|
|
|
|
// addDrawingContentTypePart provides function to add image part relationships
|
|
|
|
// in http://purl.oclc.org/ooxml/officeDocument/relationships/image and
|
|
|
|
// appropriate content type.
|
|
|
|
func (f *File) addDrawingContentTypePart(index int) {
|
|
|
|
f.setContentTypePartImageExtensions()
|
|
|
|
var content xlsxTypes
|
|
|
|
xml.Unmarshal([]byte(f.readXML("[Content_Types].xml")), &content)
|
2017-01-17 19:06:42 +08:00
|
|
|
for _, v := range content.Overrides {
|
|
|
|
if v.PartName == "/xl/drawings/drawing"+strconv.Itoa(index)+".xml" {
|
|
|
|
output, _ := xml.Marshal(content)
|
|
|
|
f.saveFileList(`[Content_Types].xml`, string(output))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content.Overrides = append(content.Overrides, xlsxOverride{
|
|
|
|
PartName: "/xl/drawings/drawing" + strconv.Itoa(index) + ".xml",
|
|
|
|
ContentType: "application/vnd.openxmlformats-officedocument.drawing+xml",
|
|
|
|
})
|
|
|
|
output, _ := xml.Marshal(content)
|
2017-01-24 18:29:02 +08:00
|
|
|
f.saveFileList("[Content_Types].xml", string(output))
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
2017-01-18 16:05:01 +08:00
|
|
|
// getSheetRelationshipsTargetByID provides function to get Target attribute
|
|
|
|
// value in xl/worksheets/_rels/sheet%d.xml.rels by given sheet name and
|
|
|
|
// relationship index.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) getSheetRelationshipsTargetByID(sheet string, rID string) string {
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
|
|
|
|
var sheetRels xlsxWorkbookRels
|
|
|
|
xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
|
|
|
|
for _, v := range sheetRels.Relationships {
|
|
|
|
if v.ID == rID {
|
|
|
|
return v.Target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|