Prechádzať zdrojové kódy

Fix Panic When View Columns Exceeds Actual Data Width

James Welch 9 rokov pred
rodič
commit
63449e02c5
1 zmenil súbory, kde vykonal 16 pridanie a 11 odobranie
  1. 16 11
      lib.go

+ 16 - 11
lib.go

@@ -585,18 +585,23 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File, sheet *Sheet) ([]*R
 				insertColIndex++
 				insertColIndex++
 			}
 			}
 			cellX := insertColIndex
 			cellX := insertColIndex
-			cell := row.Cells[cellX]
-			cell.HMerge = h
-			cell.VMerge = v
-			fillCellData(rawcell, reftable, sharedFormulas, cell)
-			if file.styles != nil {
-				cell.style = file.styles.getStyle(rawcell.S)
-				cell.NumFmt = file.styles.getNumberFormat(rawcell.S)
+
+			// K1000000: Prevent panic when the range specified in the spreadsheet
+			//           view exceeds the actual number of columns in the dataset.
+			if cellX < len(row.Cells) {
+				cell := row.Cells[cellX]
+				cell.HMerge = h
+				cell.VMerge = v
+				fillCellData(rawcell, reftable, sharedFormulas, cell)
+				if file.styles != nil {
+					cell.style = file.styles.getStyle(rawcell.S)
+					cell.NumFmt = file.styles.getNumberFormat(rawcell.S)
+				}
+				cell.date1904 = file.Date1904
+				// Cell is considered hidden if the row or the column of this cell is hidden
+				cell.Hidden = rawrow.Hidden || (len(cols) > cellX && cols[cellX].Hidden)
+				insertColIndex++
 			}
 			}
-			cell.date1904 = file.Date1904
-			// Cell is considered hidden if the row or the column of this cell is hidden
-			cell.Hidden = rawrow.Hidden || (len(cols) > cellX && cols[cellX].Hidden)
-			insertColIndex++
 		}
 		}
 		if len(rows) > insertRowIndex {
 		if len(rows) > insertRowIndex {
 			rows[insertRowIndex] = row
 			rows[insertRowIndex] = row