Skip to content

Commit b936343

Browse files
committed
This closes #2068, breaking changes: SetCellInt function required int64 data type parameter
- Update unit tests
1 parent e9efc47 commit b936343

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

cell.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ func (f *File) setCellIntFunc(sheet, cell string, value interface{}) error {
207207
var err error
208208
switch v := value.(type) {
209209
case int:
210-
err = f.SetCellInt(sheet, cell, v)
210+
err = f.SetCellInt(sheet, cell, int64(v))
211211
case int8:
212-
err = f.SetCellInt(sheet, cell, int(v))
212+
err = f.SetCellInt(sheet, cell, int64(v))
213213
case int16:
214-
err = f.SetCellInt(sheet, cell, int(v))
214+
err = f.SetCellInt(sheet, cell, int64(v))
215215
case int32:
216-
err = f.SetCellInt(sheet, cell, int(v))
216+
err = f.SetCellInt(sheet, cell, int64(v))
217217
case int64:
218-
err = f.SetCellInt(sheet, cell, int(v))
218+
err = f.SetCellInt(sheet, cell, v)
219219
case uint:
220220
err = f.SetCellUint(sheet, cell, uint64(v))
221221
case uint8:
@@ -288,7 +288,7 @@ func setCellDuration(value time.Duration) (t string, v string) {
288288

289289
// SetCellInt provides a function to set int type value of a cell by given
290290
// worksheet name, cell reference and cell value.
291-
func (f *File) SetCellInt(sheet, cell string, value int) error {
291+
func (f *File) SetCellInt(sheet, cell string, value int64) error {
292292
f.mu.Lock()
293293
ws, err := f.workSheetReader(sheet)
294294
if err != nil {
@@ -309,8 +309,8 @@ func (f *File) SetCellInt(sheet, cell string, value int) error {
309309
}
310310

311311
// setCellInt prepares cell type and string type cell value by a given integer.
312-
func setCellInt(value int) (t string, v string) {
313-
v = strconv.Itoa(value)
312+
func setCellInt(value int64) (t string, v string) {
313+
v = strconv.FormatInt(value, 10)
314314
return
315315
}
316316

excelize_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ func TestWriteArrayFormula(t *testing.T) {
628628
valCell := cell(1, i+firstResLine)
629629
assocCell := cell(2, i+firstResLine)
630630

631-
assert.NoError(t, f.SetCellInt("Sheet1", valCell, values[i]))
631+
assert.NoError(t, f.SetCellInt("Sheet1", valCell, int64(values[i])))
632632
assert.NoError(t, f.SetCellStr("Sheet1", assocCell, sample[assoc[i]]))
633633
}
634634

@@ -642,8 +642,8 @@ func TestWriteArrayFormula(t *testing.T) {
642642
stdevCell := cell(i+2, 4)
643643
calcStdevCell := cell(i+2, 5)
644644

645-
assert.NoError(t, f.SetCellInt("Sheet1", calcAvgCell, average(i)))
646-
assert.NoError(t, f.SetCellInt("Sheet1", calcStdevCell, stdev(i)))
645+
assert.NoError(t, f.SetCellInt("Sheet1", calcAvgCell, int64(average(i))))
646+
assert.NoError(t, f.SetCellInt("Sheet1", calcStdevCell, int64(stdev(i))))
647647

648648
// Average can be done with AVERAGEIF
649649
assert.NoError(t, f.SetCellFormula("Sheet1", avgCell, fmt.Sprintf("ROUND(AVERAGEIF(%s,%s,%s),0)", assocRange, nameCell, valRange)))

sheet_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func BenchmarkNewSheet(b *testing.B) {
675675
func newSheetWithSet() {
676676
file := NewFile()
677677
for i := 0; i < 1000; i++ {
678-
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), i)
678+
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), int64(i))
679679
}
680680
file = nil
681681
}
@@ -691,7 +691,7 @@ func BenchmarkFile_SaveAs(b *testing.B) {
691691
func newSheetWithSave() {
692692
file := NewFile()
693693
for i := 0; i < 1000; i++ {
694-
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), i)
694+
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), int64(i))
695695
}
696696
_ = file.Save()
697697
}

stream.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,15 @@ func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) error {
557557
func setCellIntFunc(c *xlsxC, val interface{}) {
558558
switch val := val.(type) {
559559
case int:
560-
c.T, c.V = setCellInt(val)
560+
c.T, c.V = setCellInt(int64(val))
561561
case int8:
562-
c.T, c.V = setCellInt(int(val))
562+
c.T, c.V = setCellInt(int64(val))
563563
case int16:
564-
c.T, c.V = setCellInt(int(val))
564+
c.T, c.V = setCellInt(int64(val))
565565
case int32:
566-
c.T, c.V = setCellInt(int(val))
566+
c.T, c.V = setCellInt(int64(val))
567567
case int64:
568-
c.T, c.V = setCellInt(int(val))
568+
c.T, c.V = setCellInt(val)
569569
case uint:
570570
c.T, c.V = setCellUint(uint64(val))
571571
case uint8:

0 commit comments

Comments
 (0)