Fixes #195: Make GetRows return value avoid empty cell

* #195: proposed resolution to the issue

* Make GetRows return value avoid empty cell

* Update test file to fix broken testing.
formula v1.4.1
Rafael Barros 6 years ago committed by xuri
parent fabd9d013f
commit dea7ba0ec4

@ -31,10 +31,9 @@ import (
// //
func (f *File) GetRows(sheet string) [][]string { func (f *File) GetRows(sheet string) [][]string {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
rows := [][]string{}
name, ok := f.sheetMap[trimSheetName(sheet)] name, ok := f.sheetMap[trimSheetName(sheet)]
if !ok { if !ok {
return rows return [][]string{}
} }
if xlsx != nil { if xlsx != nil {
output, _ := xml.Marshal(f.Sheet[name]) output, _ := xml.Marshal(f.Sheet[name])
@ -44,15 +43,12 @@ func (f *File) GetRows(sheet string) [][]string {
d := f.sharedStringsReader() d := f.sharedStringsReader()
var inElement string var inElement string
var r xlsxRow var r xlsxRow
var row []string
tr, tc := f.getTotalRowsCols(name) tr, tc := f.getTotalRowsCols(name)
for i := 0; i < tr; i++ { rows := make([][]string, tr)
row = []string{} for i := range rows {
for j := 0; j <= tc; j++ { rows[i] = make([]string, tc+1)
row = append(row, "")
}
rows = append(rows, row)
} }
var row int
decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name))) decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name)))
for { for {
token, _ := decoder.Token() token, _ := decoder.Token()
@ -70,12 +66,15 @@ func (f *File) GetRows(sheet string) [][]string {
c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R)) c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
val, _ := colCell.getValueFrom(f, d) val, _ := colCell.getValueFrom(f, d)
rows[cr][c] = val rows[cr][c] = val
if val != "" {
row = r.R
}
} }
} }
default: default:
} }
} }
return rows return rows[:row]
} }
// Rows defines an iterator to a sheet // Rows defines an iterator to a sheet

Binary file not shown.
Loading…
Cancel
Save