• R/O
  • HTTP
  • SSH
  • HTTPS

excelize: 提交

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets


Commit MetaInfo

修订版dea7ba0ec43a4c29a6642d02b6edc73b8b0369f0 (tree)
时间2019-01-01 19:18:42
作者Rafael Barros <admin@rafa...>
Commiterxuri

Log Message

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.

更改概述

差异

--- a/rows.go
+++ b/rows.go
@@ -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
Binary files a/test/Book1.xlsx and b/test/Book1.xlsx differ
Show on old repository browser