|
|
@ -177,27 +177,25 @@ func (f *File) addSheetRelationships(sheet, relType, target, targetMode string)
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var sheetRels xlsxWorkbookRels
|
|
|
|
sheetRels := f.workSheetRelsReader(rels)
|
|
|
|
|
|
|
|
if sheetRels == nil {
|
|
|
|
|
|
|
|
sheetRels = &xlsxWorkbookRels{}
|
|
|
|
|
|
|
|
}
|
|
|
|
var rID = 1
|
|
|
|
var rID = 1
|
|
|
|
var ID bytes.Buffer
|
|
|
|
var ID bytes.Buffer
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString("rId")
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
_, ok = f.XLSX[rels]
|
|
|
|
ID.Reset()
|
|
|
|
if ok {
|
|
|
|
rID = len(sheetRels.Relationships) + 1
|
|
|
|
ID.Reset()
|
|
|
|
ID.WriteString("rId")
|
|
|
|
_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels)
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
rID = len(sheetRels.Relationships) + 1
|
|
|
|
|
|
|
|
ID.WriteString("rId")
|
|
|
|
|
|
|
|
ID.WriteString(strconv.Itoa(rID))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sheetRels.Relationships = append(sheetRels.Relationships, xlsxWorkbookRelation{
|
|
|
|
sheetRels.Relationships = append(sheetRels.Relationships, xlsxWorkbookRelation{
|
|
|
|
ID: ID.String(),
|
|
|
|
ID: ID.String(),
|
|
|
|
Type: relType,
|
|
|
|
Type: relType,
|
|
|
|
Target: target,
|
|
|
|
Target: target,
|
|
|
|
TargetMode: targetMode,
|
|
|
|
TargetMode: targetMode,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
output, _ := xml.Marshal(sheetRels)
|
|
|
|
f.WorkSheetRels[rels] = sheetRels
|
|
|
|
f.saveFileList(rels, output)
|
|
|
|
|
|
|
|
return rID
|
|
|
|
return rID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -210,15 +208,16 @@ func (f *File) deleteSheetRelationships(sheet, rID string) {
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var sheetRels xlsxWorkbookRels
|
|
|
|
sheetRels := f.workSheetRelsReader(rels)
|
|
|
|
_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels)
|
|
|
|
if sheetRels == nil {
|
|
|
|
|
|
|
|
sheetRels = &xlsxWorkbookRels{}
|
|
|
|
|
|
|
|
}
|
|
|
|
for k, v := range sheetRels.Relationships {
|
|
|
|
for k, v := range sheetRels.Relationships {
|
|
|
|
if v.ID == rID {
|
|
|
|
if v.ID == rID {
|
|
|
|
sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...)
|
|
|
|
sheetRels.Relationships = append(sheetRels.Relationships[:k], sheetRels.Relationships[k+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output, _ := xml.Marshal(sheetRels)
|
|
|
|
f.WorkSheetRels[rels] = sheetRels
|
|
|
|
f.saveFileList(rels, output)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// addSheetLegacyDrawing provides a function to add legacy drawing element to
|
|
|
|
// addSheetLegacyDrawing provides a function to add legacy drawing element to
|
|
|
@ -441,8 +440,10 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
name = strings.ToLower(sheet) + ".xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
|
|
|
var sheetRels xlsxWorkbookRels
|
|
|
|
sheetRels := f.workSheetRelsReader(rels)
|
|
|
|
_ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML(rels)), &sheetRels)
|
|
|
|
if sheetRels == nil {
|
|
|
|
|
|
|
|
sheetRels = &xlsxWorkbookRels{}
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, v := range sheetRels.Relationships {
|
|
|
|
for _, v := range sheetRels.Relationships {
|
|
|
|
if v.ID == rID {
|
|
|
|
if v.ID == rID {
|
|
|
|
return v.Target
|
|
|
|
return v.Target
|
|
|
|