grate icon indicating copy to clipboard operation
grate copied to clipboard

[improvement] Change date format behaviour on error

Open la-chemin opened this issue 2 years ago • 0 comments

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)
	}
}

la-chemin avatar Sep 26 '23 09:09 la-chemin