From 8ef44e6d998ba03d5555233f3cbf171095dd76a8 Mon Sep 17 00:00:00 2001 From: Davian The Phoenix Date: Sat, 24 May 2025 14:37:51 +0700 Subject: [PATCH] fix issues open xlsx file on windows EOF --- xlsx/sheets.go | 2 +- xlsx/workbook.go | 2 +- xlsx/xlsx.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xlsx/sheets.go b/xlsx/sheets.go index fc9c76b..fa7b499 100644 --- a/xlsx/sheets.go +++ b/xlsx/sheets.go @@ -33,7 +33,7 @@ func (s *Sheet) parseSheet() error { linkmap := make(map[string]string) base := filepath.Base(s.docname) sub := strings.TrimSuffix(s.docname, base) - relsname := filepath.Join(sub, "_rels", base+".rels") + relsname := strings.ReplaceAll(filepath.Join(sub, "_rels", base+".rels"), "\\", "/") // fix the sep in zip file is still "/" but on windows is "\" dec, clo, err := s.d.openXML(relsname) if err == nil { // rels might not exist for every sheet diff --git a/xlsx/workbook.go b/xlsx/workbook.go index d789562..b8f33f7 100644 --- a/xlsx/workbook.go +++ b/xlsx/workbook.go @@ -32,7 +32,7 @@ func (d *Document) parseRels(dec *xml.Decoder, basedir string) error { // handle malformed "absolute" paths cleanly d.rels[vals["Type"]][vals["Id"]] = vals["Target"][1:] } else { - d.rels[vals["Type"]][vals["Id"]] = filepath.Join(basedir, vals["Target"]) + d.rels[vals["Type"]][vals["Id"]] = strings.ReplaceAll(filepath.Join(basedir, vals["Target"]), "\\", "/") // fix EOF in windows for sep being "\" instead of "/" } if vals["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" { d.primaryDoc = vals["Target"] diff --git a/xlsx/xlsx.go b/xlsx/xlsx.go index 3d5eaad..4a6ff3c 100644 --- a/xlsx/xlsx.go +++ b/xlsx/xlsx.go @@ -79,7 +79,7 @@ func Open(filename string) (grate.Source, error) { // parse the secondary relationships to primary doc base := filepath.Base(d.primaryDoc) sub := strings.TrimSuffix(d.primaryDoc, base) - relfn := filepath.Join(sub, "_rels", base+".rels") + relfn := strings.ReplaceAll(filepath.Join(sub, "_rels", base+".rels"), "\\", "/") // fix EOF in windows for sep being "\" instead of "/" dec, c, err = d.openXML(relfn) if err != nil { return nil, err