Jelajahi Sumber

Change complete rows logic to fix call `SetCellValue`makes file corruption in some case.

Ri Xu 9 tahun lalu
induk
melakukan
a16d2ec83b
1 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 6 2
      excelize.go

+ 6 - 2
excelize.go

@@ -138,8 +138,12 @@ func completeCol(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
 
 
 // Completion row element tags of XML in a sheet.
 // Completion row element tags of XML in a sheet.
 func completeRow(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
 func completeRow(xlsx xlsxWorksheet, row int, cell int) xlsxWorksheet {
-	if len(xlsx.SheetData.Row) >= row {
-		row = len(xlsx.SheetData.Row)
+	currentRows := len(xlsx.SheetData.Row)
+	if currentRows > 1 {
+		lastRow := xlsx.SheetData.Row[currentRows-1].R
+		if lastRow >= row {
+			row = lastRow
+		}
 	}
 	}
 	sheetData := xlsxSheetData{}
 	sheetData := xlsxSheetData{}
 	existsRows := map[int]int{}
 	existsRows := map[int]int{}