Browse Source

SetColWidth index out of range issue #268

rentiansheng 7 years ago
parent
commit
b8f2653249
2 changed files with 4 additions and 7 deletions
  1. 4 2
      sheet.go
  2. 0 5
      sheet_test.go

+ 4 - 2
sheet.go

@@ -72,6 +72,7 @@ func (s *Sheet) maybeAddCol(cellCount int) {
 			s.Cols = append(s.Cols, col)
 			currIndex++
 		}
+
 		s.MaxCol = cellCount
 	}
 }
@@ -111,8 +112,9 @@ func (s *Sheet) SetColWidth(startcol, endcol int, width float64) error {
 	if startcol > endcol {
 		return fmt.Errorf("Could not set width for range %d-%d: startcol must be less than endcol.", startcol, endcol)
 	}
-	s.maybeAddCol(endcol + 1)
-	for ; startcol <= endcol; startcol++ {
+	end := endcol + 1
+	s.maybeAddCol(end)
+	for ; startcol < end; startcol++ {
 		s.Cols[startcol].Width = width
 	}
 

+ 0 - 5
sheet_test.go

@@ -232,13 +232,8 @@ func (s *SheetSuite) TestSetColWidth(c *C) {
 	sheet, _ := file.AddSheet("Sheet1")
 	_ = sheet.SetColWidth(0, 0, 10.5)
 	_ = sheet.SetColWidth(1, 5, 11)
-
 	c.Assert(sheet.Cols[0].Width, Equals, 10.5)
-	c.Assert(sheet.Cols[0].Max, Equals, 1)
-	c.Assert(sheet.Cols[0].Min, Equals, 1)
 	c.Assert(sheet.Cols[1].Width, Equals, float64(11))
-	c.Assert(sheet.Cols[1].Max, Equals, 6)
-	c.Assert(sheet.Cols[1].Min, Equals, 2)
 }
 
 func (s *SheetSuite) TestSetRowHeightCM(c *C) {