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

excelize按行读取内容成字符串数组导致日期格式错误 #1868

Closed
943885179 opened this issue Apr 1, 2024 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists

Comments

@943885179
Copy link

1.准备测试数据,wps正常编辑日期。
image
正常输入2024-03-25,wps会自动转成2024/3/25,为日期格式
但是通过下面代码读取,读取到的为[]string,数据异常。03-25-24
此问题会导致我输入的日期是2024-03-25 或1924-03-25 都是03-25-24

        rows, _ := f.Rows(sheet)
	for rows.Next() {
		row, err := rows.Columns(opts...)
               //上面的row返回的是[]string,解析出的日期格式异常
		if err != nil {
			break
		}
	}
@xuri
Copy link
Member

xuri commented Apr 1, 2024

Thanks for your issue. This was duplicated with issues #1157 and #1199. Please reference the documentation, this library supports specified system date and time format codes in the options when creating or opening the workbook. The built-in number format 14 and some date formats that begin with an asterisk (*) in the spreadsheet application's number format setting window were affected by system short date, long date, and long time settings. Now we can set these settings by ShortDatePattern, LongDatePattern, and LongTimePattern fields in the Options. For example, now you can open a workbook with custom date and time options like this:

f, err := excelize.OpenFile("Book1.xlsx", excelize.Options{
    ShortDatePattern: "yyyy/mm/dd",
})

After that, if you get a cell value with built-in number format ID 14, the number will be formatted with yyyy/mm/dd. This feature will be released in the next version. I'll close this, if you have any questions, please let me know, and you can reopen this anytime.

@xuri xuri closed this as completed Apr 1, 2024
@xuri xuri added the duplicate This issue or pull request already exists label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants