未验证 提交 a258e3d8 编写于 作者: F funa12 提交者: GitHub

Fix CalcCellValue does not return raw value when enable RawCellValue (#1803)

上级 99e91e19
......@@ -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
......
......@@ -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{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册