Skip to content

Commit

Permalink
Fix CalcCellValue does not return raw value when enable RawCellValue (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
funa12 committed Feb 2, 2024
1 parent 99e91e1 commit a258e3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string
styleIdx, _ = f.GetCellStyle(sheet, cell)
}
result = token.Value()
if isNum, precision, decimal := isNumeric(result); isNum {
if isNum, precision, decimal := isNumeric(result); isNum && !rawCellValue {
if precision > 15 {
result, err = f.formattedValue(&xlsxC{S: styleIdx, V: strings.ToUpper(strconv.FormatFloat(decimal, 'G', 15, 64))}, rawCellValue, CellTypeNumber)
return
Expand Down
22 changes: 22 additions & 0 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6301,6 +6301,28 @@ func TestNestedFunctionsWithOperators(t *testing.T) {
}
}

func TestFormulaRawCellValueOption(t *testing.T) {
f := NewFile()
rawTest := []struct {
value string
raw bool
expected string
}{
{"=\"10e3\"", false, "10000"},
{"=\"10e3\"", true, "10e3"},
{"=\"10\" & \"e3\"", false, "10000"},
{"=\"10\" & \"e3\"", true, "10e3"},
{"=\"1111111111111111\"", false, "1.11111111111111E+15"},
{"=\"1111111111111111\"", true, "1111111111111111"},
}
for _, test := range rawTest {
assert.NoError(t, f.SetCellFormula("Sheet1", "A1", test.value))
val, err := f.CalcCellValue("Sheet1", "A1", Options{RawCellValue: test.raw})
assert.NoError(t, err)
assert.Equal(t, test.expected, val)
}
}

func TestFormulaArgToToken(t *testing.T) {
assert.Equal(t,
efp.Token{
Expand Down

0 comments on commit a258e3d

Please sign in to comment.