From 48f19f60aa3e162146a9dc4edf7b4c8cf687ec26 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 27 Jun 2020 00:02:47 +0800 Subject: support the row element without r attribute in the worksheet --- excelize.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'excelize.go') diff --git a/excelize.go b/excelize.go index 3e0255a..970759c 100644 --- a/excelize.go +++ b/excelize.go @@ -191,16 +191,25 @@ func (f *File) workSheetReader(sheet string) (xlsx *xlsxWorksheet, err error) { // checkSheet provides a function to fill each row element and make that is // continuous in a worksheet of XML. func checkSheet(xlsx *xlsxWorksheet) { - row := len(xlsx.SheetData.Row) - if row >= 1 { - lastRow := xlsx.SheetData.Row[row-1].R - if lastRow >= row { - row = lastRow + var row int + for _, r := range xlsx.SheetData.Row { + if r.R != 0 && r.R > row { + row = r.R + continue } + row++ } sheetData := xlsxSheetData{Row: make([]xlsxRow, row)} + row = 0 for _, r := range xlsx.SheetData.Row { - sheetData.Row[r.R-1] = r + if r.R != 0 { + sheetData.Row[r.R-1] = r + row = r.R + continue + } + row++ + r.R = row + sheetData.Row[row-1] = r } for i := 1; i <= row; i++ { sheetData.Row[i-1].R = i -- cgit v1.2.1