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

Support date formats with dot separator such as DD.MM.YYYY #7

Closed
nicomni opened this issue Sep 17, 2023 · 2 comments · Fixed by #8
Closed

Support date formats with dot separator such as DD.MM.YYYY #7

nicomni opened this issue Sep 17, 2023 · 2 comments · Fixed by #8

Comments

@nicomni
Copy link
Contributor

nicomni commented Sep 17, 2023

Is your feature request related to a problem? Please describe.
When using excelize to read an Excel workbook with dates formatted as DD.MM.YYYY it results in ..YYYY, e.g. 18.11.2023 is parsed as ..2023.

Describe the solution you'd like
Once the parser sees the dot ., it interprets this as a TokenTypeDecimal and discards the preceding datetime values, e.g. parsing MM. results in a . token.
I want to see an MM token of TokenTypeDatetime and a . of type TokenTypeLiteral being added to the tokens list.

Describe alternatives you've considered

Additional context

@xuri
Copy link
Owner

xuri commented Sep 17, 2023

Thanks for your issue. I have tested number format code DD.MM.YYYY with the excelize master branch, and it works well. Please try to upgrade master branch code, if still have this problem, please let me know.

@nicomni
Copy link
Contributor Author

nicomni commented Sep 17, 2023

Sorry for not adding more context. Let me rectify:

The problem occurs when the datetime is stored as a float in the specific cell rather than a shared string, and a custom format code is used. See this example:

package main

import (
	"fmt"
	"log"

	"github.com/xuri/excelize/v2"
)

func main() {
	f := excelize.NewFile()
	defer func() {
		if err := f.Close(); err != nil {
			log.Fatal(err)
		}
	}()
        activeSheetName := f.GetSheetName(f.GetActiveSheetIndex())
	f.SetCellValue(activeSheetName, "A1", 45186.0)
	exp := "DD.MM.YYYY"
	style, _ := f.NewStyle(&excelize.Style{CustomNumFmt: &exp})
	f.SetColStyle(activeSheetName, "A", style)
	val, _ := f.GetCellValue(activeSheetName, "A1")
	fmt.Println(val) // Getting '..2023'. Want '17.09.2023'
}

During execution, the circumstances lead to this line in the excelize codebase to be run, which ultimately lead to nfp.format() to be called.

I have addressed the issue in #8

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

Successfully merging a pull request may close this issue.

2 participants