diff options
author | xuri <xuri.me@gmail.com> | 2021-02-27 00:03:46 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-02-27 08:49:10 +0800 |
commit | afe2ebc26143330a15b4396b9be6ca04797a5e8e (patch) | |
tree | 3444cab434de14a0cc8d8a9c1d62c35179ffcc54 /sheet.go | |
parent | 5a0d885315521a4e703f9de401e2dda834285d5f (diff) |
This improves compatibility for absolute XML path, Windows-style directory separator and inline namespace;
Diffstat (limited to 'sheet.go')
-rw-r--r-- | sheet.go | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -157,6 +157,9 @@ func (f *File) workSheetWriter() { for k, v := range sheet.SheetData.Row { f.Sheet[p].SheetData.Row[k].C = trimCell(v.C) } + if sheet.SheetPr != nil || sheet.Drawing != nil || sheet.Hyperlinks != nil || sheet.Picture != nil || sheet.TableParts != nil { + f.addNameSpaces(p, SourceRelationship) + } // reusing buffer _ = encoder.Encode(sheet) f.saveFileList(p, replaceRelationshipsBytes(f.replaceNameSpaceBytes(p, buffer.Bytes()))) @@ -455,7 +458,11 @@ func (f *File) getSheetMap() map[string]string { // path, compatible with different types of relative paths in // workbook.xml.rels, for example: worksheets/sheet%d.xml // and /xl/worksheets/sheet%d.xml - path := filepath.ToSlash(strings.TrimPrefix(filepath.Clean(fmt.Sprintf("%s/%s", filepath.Dir(f.getWorkbookPath()), rel.Target)), "/")) + path := filepath.ToSlash(strings.TrimPrefix( + strings.Replace(filepath.Clean(fmt.Sprintf("%s/%s", filepath.Dir(f.getWorkbookPath()), rel.Target)), "\\", "/", -1), "/")) + if strings.HasPrefix(rel.Target, "/") { + path = filepath.ToSlash(strings.TrimPrefix(strings.Replace(filepath.Clean(rel.Target), "\\", "/", -1), "/")) + } if _, ok := f.XLSX[path]; ok { maps[v.Name] = path } |