Skip to content

Commit dea7ba0

Browse files
rafaelmitixuri
authored andcommitted
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.
1 parent fabd9d0 commit dea7ba0

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

rows.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import (
3131
//
3232
func (f *File) GetRows(sheet string) [][]string {
3333
xlsx := f.workSheetReader(sheet)
34-
rows := [][]string{}
3534
name, ok := f.sheetMap[trimSheetName(sheet)]
3635
if !ok {
37-
return rows
36+
return [][]string{}
3837
}
3938
if xlsx != nil {
4039
output, _ := xml.Marshal(f.Sheet[name])
@@ -44,15 +43,12 @@ func (f *File) GetRows(sheet string) [][]string {
4443
d := f.sharedStringsReader()
4544
var inElement string
4645
var r xlsxRow
47-
var row []string
4846
tr, tc := f.getTotalRowsCols(name)
49-
for i := 0; i < tr; i++ {
50-
row = []string{}
51-
for j := 0; j <= tc; j++ {
52-
row = append(row, "")
53-
}
54-
rows = append(rows, row)
47+
rows := make([][]string, tr)
48+
for i := range rows {
49+
rows[i] = make([]string, tc+1)
5550
}
51+
var row int
5652
decoder := xml.NewDecoder(bytes.NewReader(f.readXML(name)))
5753
for {
5854
token, _ := decoder.Token()
@@ -70,12 +66,15 @@ func (f *File) GetRows(sheet string) [][]string {
7066
c := TitleToNumber(strings.Map(letterOnlyMapF, colCell.R))
7167
val, _ := colCell.getValueFrom(f, d)
7268
rows[cr][c] = val
69+
if val != "" {
70+
row = r.R
71+
}
7372
}
7473
}
7574
default:
7675
}
7776
}
78-
return rows
77+
return rows[:row]
7978
}
8079

8180
// Rows defines an iterator to a sheet

test/Book1.xlsx

-2.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)