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

How to read date from excel sheet #1126

Closed
ifat420 opened this issue Jan 19, 2022 · 4 comments
Closed

How to read date from excel sheet #1126

ifat420 opened this issue Jan 19, 2022 · 4 comments

Comments

@ifat420
Copy link

ifat420 commented Jan 19, 2022

In the Excel file there is a cell:
E7 => 3/14/2000

I'm trying to get it...

cell, err := f.GetCellValue("Sheet1", "E7")
    if err != nil {
        fmt.Println(err)
        return
    }
println(cell)

Output: 03-14-00

output as sting format.
How can I convert it into go time.Time format
Thanks

@xuri
Copy link
Member

xuri commented Jan 19, 2022

Thanks for your issue, you can read raw cell values and convert them to time.Time by ExcelDateToTime like this:

cell, err := f.GetCellValue("Sheet1", "E7", excelize.Options{RawCellValue: true})
if err != nil {
    fmt.Println(err)
    return
}
excelDate, err := strconv.ParseFloat(cell, 64)
if err != nil {
    fmt.Println(err)
    return
}
excelTime, err := excelize.ExcelDateToTime(excelDate, false)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(excelTime)

@ifat420
Copy link
Author

ifat420 commented Jan 19, 2022

Thanks for your issue, you can read raw cell values and convert them to time.Time by ExcelDateToTime like this:

cell, err := f.GetCellValue("Sheet1", "E7", excelize.Options{RawCellValue: true})
if err != nil {
    fmt.Println(err)
    return
}
excelDate, err := strconv.ParseFloat(cell, 64)
if err != nil {
    fmt.Println(err)
    return
}
excelTime, err := excelize.ExcelDateToTime(excelDate, false)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(excelTime)

Thanks dude

@SmartZou
Copy link

When I use f.GetRows mode to read data, the above reference code output is a fixed value. The code is as follows
rows, _ := f.GetRows(config.BasicInformationSheetName)

image

@xuri
Copy link
Member

xuri commented Mar 23, 2022

Hi @SmartZou, which version of the library you're using? Please give a try with the master branch code, and if it still not work please provide your input file attachment without confidential info if you can.

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

3 participants