Skip to content

Commit 5bf3ea6

Browse files
committed
This closes qax-os#842, avoid empty rows in the tail of the worksheet
1 parent c8c62c2 commit 5bf3ea6

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Introduction
1515

16-
Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX / XLSM / XLTM files. Supports reading and writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports complex components by high compatibility, and provided streaming API for generating or reading data from a worksheet with huge amounts of data. This library needs Go version 1.15 or later. The full API docs can be seen using go's built-in documentation tool, or online at [go.dev](https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc) and [docs reference](https://xuri.me/excelize/).
16+
Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX / XLSM / XLTM / XLTX files. Supports reading and writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports complex components by high compatibility, and provided streaming API for generating or reading data from a worksheet with huge amounts of data. This library needs Go version 1.15 or later. The full API docs can be seen using go's built-in documentation tool, or online at [go.dev](https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc) and [docs reference](https://xuri.me/excelize/).
1717

1818
## Basic Usage
1919

Diff for: README_zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## 简介
1515

16-
Excelize 是 Go 语言编写的用于操作 Office Excel 文档基础库,基于 ECMA-376,ISO/IEC 29500 国际标准。可以使用它来读取、写入由 Microsoft Excel™ 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM 等多种文档格式,高度兼容带有样式、图片(表)、透视表、切片器等复杂组件的文档,并提供流式读写 API,用于处理包含大规模数据的工作簿。可应用于各类报表平台、云计算、边缘计算等系统。使用本类库要求使用的 Go 语言为 1.15 或更高版本,完整的 API 使用文档请访问 [go.dev](https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc) 或查看 [参考文档](https://xuri.me/excelize/)
16+
Excelize 是 Go 语言编写的用于操作 Office Excel 文档基础库,基于 ECMA-376,ISO/IEC 29500 国际标准。可以使用它来读取、写入由 Microsoft Excel™ 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式,高度兼容带有样式、图片(表)、透视表、切片器等复杂组件的文档,并提供流式读写 API,用于处理包含大规模数据的工作簿。可应用于各类报表平台、云计算、边缘计算等系统。使用本类库要求使用的 Go 语言为 1.15 或更高版本,完整的 API 使用文档请访问 [go.dev](https://pkg.go.dev/github.com/360EntSecGroup-Skylar/excelize/v2?tab=doc) 或查看 [参考文档](https://xuri.me/excelize/)
1717

1818
## 快速上手
1919

Diff for: rows.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ func (f *File) GetRows(sheet string) ([][]string, error) {
4343
if err != nil {
4444
return nil, err
4545
}
46-
results := make([][]string, 0, 64)
46+
results, cur, max := make([][]string, 0, 64), 0, 0
4747
for rows.Next() {
48+
cur++
4849
row, err := rows.Columns()
4950
if err != nil {
5051
break
5152
}
5253
results = append(results, row)
54+
if len(row) > 0 {
55+
max = cur
56+
}
5357
}
54-
return results, nil
58+
return results[:max], nil
5559
}
5660

5761
// Rows defines an iterator to a sheet.
@@ -161,7 +165,9 @@ func rowXMLHandler(rowIterator *rowXMLIterator, xmlElement *xml.StartElement) {
161165
}
162166
blank := rowIterator.cellCol - len(rowIterator.columns)
163167
val, _ := colCell.getValueFrom(rowIterator.rows.f, rowIterator.d)
164-
rowIterator.columns = append(appendSpace(blank, rowIterator.columns), val)
168+
if val != "" {
169+
rowIterator.columns = append(appendSpace(blank, rowIterator.columns), val)
170+
}
165171
}
166172
}
167173

0 commit comments

Comments
 (0)