Browse Source

fixed sheet.Col index out of range fixed #378

rentiansheng 7 years ago
parent
commit
c0637e6b3e
1 changed files with 11 additions and 7 deletions
  1. 11 7
      sheet.go

+ 11 - 7
sheet.go

@@ -59,13 +59,17 @@ func (s *Sheet) AddRow() *Row {
 // Make sure we always have as many Cols as we do cells.
 func (s *Sheet) maybeAddCol(cellCount int) {
 	if cellCount > s.MaxCol {
-		col := &Col{
-			style:     NewStyle(),
-			Min:       cellCount,
-			Max:       cellCount,
-			Hidden:    false,
-			Collapsed: false}
-		s.Cols = append(s.Cols, col)
+		loopCnt := cellCount - s.MaxCol
+		for i := 0; i < loopCnt; i++ {
+			col := &Col{
+				style:     NewStyle(),
+				Min:       cellCount,
+				Max:       cellCount,
+				Hidden:    false,
+				Collapsed: false}
+			s.Cols = append(s.Cols, col)
+		}
+
 		s.MaxCol = cellCount
 	}
 }