From c922c32fb7571d3d40d3244e5635142bc390a3db Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 18 Jul 2020 15:15:16 +0800 Subject: support parse and generate XML element namespace dynamic, fix #651 --- rows.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'rows.go') diff --git a/rows.go b/rows.go index 535b010..320ba2f 100644 --- a/rows.go +++ b/rows.go @@ -121,11 +121,8 @@ func (rows *Rows) Columns() ([]string, error) { } } blank := cellCol - len(columns) - for i := 1; i < blank; i++ { - columns = append(columns, "") - } val, _ := colCell.getValueFrom(rows.f, d) - columns = append(columns, val) + columns = append(appendSpace(blank, columns), val) } case xml.EndElement: inElement = startElement.Name.Local @@ -137,6 +134,14 @@ func (rows *Rows) Columns() ([]string, error) { return columns, err } +// appendSpace append blank characters to slice by given length and source slice. +func appendSpace(l int, s []string) []string { + for i := 1; i < l; i++ { + s = append(s, "") + } + return s +} + // ErrSheetNotExist defines an error of sheet is not exist type ErrSheetNotExist struct { SheetName string @@ -173,7 +178,7 @@ func (f *File) Rows(sheet string) (*Rows, error) { if f.Sheet[name] != nil { // flush data output, _ := xml.Marshal(f.Sheet[name]) - f.saveFileList(name, replaceRelationshipsNameSpaceBytes(output)) + f.saveFileList(name, f.replaceNameSpaceBytes(name, output)) } var ( err error -- cgit v1.2.1