Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalcCellValue doesn't work as expected with DATEVALUE #1435

Open
peric opened this issue Dec 30, 2022 · 2 comments
Open

CalcCellValue doesn't work as expected with DATEVALUE #1435

peric opened this issue Dec 30, 2022 · 2 comments

Comments

@peric
Copy link

peric commented Dec 30, 2022

Description

I'm using CalcCellValue in order to calculate the value previously set with the SetCellFormula. In this specific case, I am using a DATEVALUE formula. Basically, what I do is something like this:

err = f.SetCellFormula(firstSheet, "K2", "DATEVALUE(\"2.7.2023\")"))
if err != nil {
    logger.WithErr(err).Debug("SetCellFormula error")
    return nil, nil, err
}

cellValue, err = f.CalcCellValue(firstSheet, "K2")
if err != nil {
    logger.WithErr(err).Debug("CalcCellValue error")
    return nil, nil, err
}

Describe the results you received:

From the example above, I will always receive #VALUE! in the err.

On the other side, I have also tried another simple example and this works as expected aka I receive 1 as a cellValue.

err = f.SetCellFormula(firstSheet, "K2", "ABS(-1)")
if err != nil {
    logger.WithErr(err).Debug("SetCellFormula error")
    return nil, nil, err
}
					
cellValue, err = f.CalcCellValue(firstSheet, "K2")
if err != nil {
    logger.WithErr(err).Debug("CalcCellValue error")
    return nil, nil, err
}

Is it possible there are some issues just with DATEVALUE or am I doing something wrong?

Describe the results you expected:

Instead of error (#VALUE!), I would expect 45109, which is the numeric value received after applying DATEVALUE on the 2.7.2023.

image

Output of go version:

go version go1.19.3 darwin/arm6

Excelize version or commit ID:

ab12307393461e7055f664d296a3a0e686eebb39

Environment details (OS, Microsoft Excel™ version, physical, etc.):

MacOS, Excel 16.68

@xuri
Copy link
Member

xuri commented Dec 31, 2022

Thanks for your issue. In Excel, the supported formats of the DATEVALUE functions date_text arguments were related to the operating system's regional format settings. Currently, this library just supports the formats of English, for example:

2/7/2023
7-feb-23
7-feb-2023
02/07/23

@peric
Copy link
Author

peric commented Jan 9, 2023

DATEVALUE

Thanks for your answer. I just saw the code that handles this. Will think through if it makes sense for us to implement some additional date formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants