pbnjay / grate

A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[improvement] Change date format behaviour on error

la-chemin opened this issue · comments

commented

It would be better to return the original cell value when apply date format fails, instead of returning error message.

A XLS file is attached that would yield unwanted error message.

testFile.xls

Below is my modifcation

func timeFmtFunc(f string) FmtFunc {
	return func(x *Formatter, v interface{}) string {
		t, ok := v.(time.Time)
		if !ok {
			fval, ok := convertToFloat64(v)
			if !ok {
				return v.(string) // convert it to string
			}
			t = x.ConvertToDate(fval)
		}
		//log.Println("formatting date", t, "with", f, "=", t.Format(f))
		return t.Format(f)
	}
}