Skip to content

Commit a2d4497

Browse files
committed
- This fix panic and incorrect cell read on some case
- Make unit test on Go 1.7 - API documentation updated
1 parent 9b55f4f commit a2d4497

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
test:
66
strategy:
77
matrix:
8-
go-version: [1.15.x, 1.16.x]
8+
go-version: [1.15.x, 1.16.x, 1.17.x]
99
os: [ubuntu-latest, macos-latest, windows-latest]
1010
targetplatform: [x86, x64]
1111

cell_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func TestGetCellValue(t *testing.T) {
181181
// Test get cell value without r attribute of the row.
182182
f := NewFile()
183183
sheetData := `<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>%s</sheetData></worksheet>`
184+
184185
f.Sheet.Delete("xl/worksheets/sheet1.xml")
185186
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row r="3"><c t="str"><v>A3</v></c></row><row><c t="str"><v>A4</v></c><c t="str"><v>B4</v></c></row><row r="7"><c t="str"><v>A7</v></c><c t="str"><v>B7</v></c></row><row><c t="str"><v>A8</v></c><c t="str"><v>B8</v></c></row>`)))
186187
f.checked = nil
@@ -196,24 +197,34 @@ func TestGetCellValue(t *testing.T) {
196197
cols, err := f.GetCols("Sheet1")
197198
assert.Equal(t, [][]string{{"", "", "A3", "A4", "", "", "A7", "A8"}, {"", "", "", "B4", "", "", "B7", "B8"}}, cols)
198199
assert.NoError(t, err)
200+
199201
f.Sheet.Delete("xl/worksheets/sheet1.xml")
200202
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row r="2"><c r="A2" t="str"><v>A2</v></c></row><row r="2"><c r="B2" t="str"><v>B2</v></c></row>`)))
201203
f.checked = nil
202204
cell, err := f.GetCellValue("Sheet1", "A2")
203205
assert.Equal(t, "A2", cell)
204206
assert.NoError(t, err)
207+
205208
f.Sheet.Delete("xl/worksheets/sheet1.xml")
206209
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row r="2"><c r="A2" t="str"><v>A2</v></c></row><row r="2"><c r="B2" t="str"><v>B2</v></c></row>`)))
207210
f.checked = nil
208211
rows, err = f.GetRows("Sheet1")
209212
assert.Equal(t, [][]string{nil, {"A2", "B2"}}, rows)
210213
assert.NoError(t, err)
214+
211215
f.Sheet.Delete("xl/worksheets/sheet1.xml")
212216
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row r="1"><c r="A1" t="str"><v>A1</v></c></row><row r="1"><c r="B1" t="str"><v>B1</v></c></row>`)))
213217
f.checked = nil
214218
rows, err = f.GetRows("Sheet1")
215219
assert.Equal(t, [][]string{{"A1", "B1"}}, rows)
216220
assert.NoError(t, err)
221+
222+
f.Sheet.Delete("xl/worksheets/sheet1.xml")
223+
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(fmt.Sprintf(sheetData, `<row><c t="str"><v>A3</v></c></row><row><c t="str"><v>A4</v></c><c t="str"><v>B4</v></c></row><row r="7"><c t="str"><v>A7</v></c><c t="str"><v>B7</v></c></row><row><c t="str"><v>A8</v></c><c t="str"><v>B8</v></c></row>`)))
224+
f.checked = nil
225+
rows, err = f.GetRows("Sheet1")
226+
assert.Equal(t, [][]string{{"A3"}, {"A4", "B4"}, nil, nil, nil, nil, {"A7", "B7"}, {"A8", "B8"}}, rows)
227+
assert.NoError(t, err)
217228
}
218229

219230
func TestGetCellFormula(t *testing.T) {

col.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ func (f *File) SetColOutlineLevel(sheet, col string, level uint8) error {
399399

400400
// SetColStyle provides a function to set style of columns by given worksheet
401401
// name, columns range and style ID. Note that this will overwrite the
402-
// existing styles for the cell, it won't append or merge style with existing
403-
// styles.
402+
// existing styles for the columns, it won't append or merge style with
403+
// existing styles.
404404
//
405405
// For example set style of column H on Sheet1:
406406
//

excelize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func checkSheet(ws *xlsxWorksheet) {
238238
sheetData := xlsxSheetData{Row: make([]xlsxRow, row)}
239239
row = 0
240240
for _, r := range ws.SheetData.Row {
241-
if r.R == row {
241+
if r.R == row && row > 0 {
242242
sheetData.Row[r.R-1].C = append(sheetData.Row[r.R-1].C, r.C...)
243243
continue
244244
}

rows.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ import (
2424
)
2525

2626
// GetRows return all the rows in a sheet by given worksheet name
27-
// (case sensitive). GetRows fetched the rows with value or formula cells,
28-
// the tail continuously empty cell will be skipped. For example:
27+
// (case sensitive), returned as a two-dimensional array, where the value of
28+
// the cell is converted to the string type. If the cell format can be
29+
// applied to the value of the cell, the applied value will be used,
30+
// otherwise the original value will be used. GetRows fetched the rows with
31+
// value or formula cells, the tail continuously empty cell will be skipped.
32+
// For example:
2933
//
3034
// rows, err := f.GetRows("Sheet1")
3135
// if err != nil {
@@ -111,7 +115,7 @@ func (rows *Rows) Columns() ([]string, error) {
111115
}
112116
case xml.EndElement:
113117
rowIterator.inElement = xmlElement.Name.Local
114-
if rowIterator.row == 0 {
118+
if rowIterator.row == 0 && rowIterator.rows.curRow > 1 {
115119
rowIterator.row = rowIterator.rows.curRow
116120
}
117121
if rowIterator.inElement == "row" && rowIterator.row+1 < rowIterator.rows.curRow {
@@ -720,9 +724,9 @@ func checkRow(ws *xlsxWorksheet) error {
720724
return nil
721725
}
722726

723-
// SetRowStyle provides a function to set style of rows by given worksheet
724-
// name, row range and style ID. Note that this will overwrite the existing
725-
// styles for the cell, it won't append or merge style with existing styles.
727+
// SetRowStyle provides a function to set the style of rows by given worksheet
728+
// name, row range, and style ID. Note that this will overwrite the existing
729+
// styles for the rows, it won't append or merge style with existing styles.
726730
//
727731
// For example set style of row 1 on Sheet1:
728732
//

styles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,8 +2603,8 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
26032603
// SetCellStyle provides a function to add style attribute for cells by given
26042604
// worksheet name, coordinate area and style ID. Note that diagonalDown and
26052605
// diagonalUp type border should be use same color in the same coordinate
2606-
// area, this will overwrite the existing styles for the cell, it won't
2607-
// append or merge style with existing styles.
2606+
// area. SetCellStyle will overwrite the existing styles for the cell, it
2607+
// won't append or merge style with existing styles.
26082608
//
26092609
// For example create a borders of cell H9 on Sheet1:
26102610
//

0 commit comments

Comments
 (0)