Skip to content

Commit

Permalink
This closes #2068, breaking changes: SetCellInt function required int…
Browse files Browse the repository at this point in the history
…64 data type parameter

- Update unit tests
  • Loading branch information
xuri committed Jan 21, 2025
1 parent e9efc47 commit b936343
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ func (f *File) setCellIntFunc(sheet, cell string, value interface{}) error {
var err error
switch v := value.(type) {
case int:
err = f.SetCellInt(sheet, cell, v)
err = f.SetCellInt(sheet, cell, int64(v))
case int8:
err = f.SetCellInt(sheet, cell, int(v))
err = f.SetCellInt(sheet, cell, int64(v))
case int16:
err = f.SetCellInt(sheet, cell, int(v))
err = f.SetCellInt(sheet, cell, int64(v))
case int32:
err = f.SetCellInt(sheet, cell, int(v))
err = f.SetCellInt(sheet, cell, int64(v))
case int64:
err = f.SetCellInt(sheet, cell, int(v))
err = f.SetCellInt(sheet, cell, v)
case uint:
err = f.SetCellUint(sheet, cell, uint64(v))
case uint8:
Expand Down Expand Up @@ -288,7 +288,7 @@ func setCellDuration(value time.Duration) (t string, v string) {

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

// setCellInt prepares cell type and string type cell value by a given integer.
func setCellInt(value int) (t string, v string) {
v = strconv.Itoa(value)
func setCellInt(value int64) (t string, v string) {
v = strconv.FormatInt(value, 10)
return
}

Expand Down
6 changes: 3 additions & 3 deletions excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func TestWriteArrayFormula(t *testing.T) {
valCell := cell(1, i+firstResLine)
assocCell := cell(2, i+firstResLine)

assert.NoError(t, f.SetCellInt("Sheet1", valCell, values[i]))
assert.NoError(t, f.SetCellInt("Sheet1", valCell, int64(values[i])))
assert.NoError(t, f.SetCellStr("Sheet1", assocCell, sample[assoc[i]]))
}

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

assert.NoError(t, f.SetCellInt("Sheet1", calcAvgCell, average(i)))
assert.NoError(t, f.SetCellInt("Sheet1", calcStdevCell, stdev(i)))
assert.NoError(t, f.SetCellInt("Sheet1", calcAvgCell, int64(average(i))))
assert.NoError(t, f.SetCellInt("Sheet1", calcStdevCell, int64(stdev(i))))

// Average can be done with AVERAGEIF
assert.NoError(t, f.SetCellFormula("Sheet1", avgCell, fmt.Sprintf("ROUND(AVERAGEIF(%s,%s,%s),0)", assocRange, nameCell, valRange)))
Expand Down
4 changes: 2 additions & 2 deletions sheet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ func BenchmarkNewSheet(b *testing.B) {
func newSheetWithSet() {
file := NewFile()
for i := 0; i < 1000; i++ {
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), i)
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), int64(i))
}
file = nil
}
Expand All @@ -691,7 +691,7 @@ func BenchmarkFile_SaveAs(b *testing.B) {
func newSheetWithSave() {
file := NewFile()
for i := 0; i < 1000; i++ {
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), i)
_ = file.SetCellInt("Sheet1", "A"+strconv.Itoa(i+1), int64(i))
}
_ = file.Save()
}
Expand Down
10 changes: 5 additions & 5 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,15 @@ func (sw *StreamWriter) setCellValFunc(c *xlsxC, val interface{}) error {
func setCellIntFunc(c *xlsxC, val interface{}) {
switch val := val.(type) {
case int:
c.T, c.V = setCellInt(val)
c.T, c.V = setCellInt(int64(val))
case int8:
c.T, c.V = setCellInt(int(val))
c.T, c.V = setCellInt(int64(val))
case int16:
c.T, c.V = setCellInt(int(val))
c.T, c.V = setCellInt(int64(val))
case int32:
c.T, c.V = setCellInt(int(val))
c.T, c.V = setCellInt(int64(val))
case int64:
c.T, c.V = setCellInt(int(val))
c.T, c.V = setCellInt(val)
case uint:
c.T, c.V = setCellUint(uint64(val))
case uint8:
Expand Down

0 comments on commit b936343

Please sign in to comment.