xls icon indicating copy to clipboard operation
xls copied to clipboard

数字转换成时间格式的问题

Open weiwolves opened this issue 7 years ago • 9 comments

Hi,我遇到一个问题: image

里面数字读出来的时候会转成时间格式,不是预想的结果,能不能增加一个选项,只输出没有转换的表格内容:

类似这样

func (xf *XfRk) String(wb *WorkBook) string { idx := int(xf.Index) if len(wb.Xfs) > idx { fNo := wb.Xfs[idx].formatNo() if fNo >= 164 { // user defined format if fmt := wb.Formats[fNo]; fmt != nil { i, f, isFloat := xf.Rk.number() if !isFloat { f = float64(i) } return strconv.FormatFloat(f, 'f', -1, 32) //t := timeFromExcelTime(f, wb.dateMode == 1)

			//return t.Format(time.RFC3339) //TODO it should be international and format as the describled style
		}
		// see http://www.openoffice.org/sc/excelfileformat.pdf
	} else if 14 <= fNo && fNo <= 17 || fNo == 22 || 27 <= fNo && fNo <= 36 || 50 <= fNo && fNo <= 58 { // jp. date format
		i, f, isFloat := xf.Rk.number()
		if !isFloat {
			f = float64(i)
		}
		return strconv.FormatFloat(f, 'f', -1, 32)
		//t := timeFromExcelTime(f, wb.dateMode == 1)
		//return t.Format("2006.01") //TODO it should be international
	}
}
return xf.Rk.String()

}

我把代码里面的时间格式转换改成了直接输出数字

weiwolves avatar Mar 08 '17 06:03 weiwolves

能否提供一下具体的xls文件,这应该是时间格式和其他格式文件混淆的缘故

extrame avatar Mar 09 '17 01:03 extrame

格式是这样子

20703-2.zip

weiwolves avatar Mar 10 '17 14:03 weiwolves

你这个格式没看到时间?

lwmonster avatar Jul 03 '17 09:07 lwmonster

@extrame 2017/01/01 11:11:00 这个时间通过row.Col(i) 读出来是 42741.4659722222 怎么处理?

lwmonster avatar Jul 03 '17 09:07 lwmonster

这个是中文地区的自定义格式问题,还没想好一个特别好的方案

在 2017年7月3日,17:50,liang [email protected] 写道:

@extrame https://github.com/extrame 2017/01/01 11:11:00 这个时间通过row.Col(i) 读出来是 42741.4659722222 怎么处理?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/extrame/xls/issues/18#issuecomment-312601420, or mute the thread https://github.com/notifications/unsubscribe-auth/ACAnNJbFtlC9AjCP-3813jXXQYpHo0eEks5sKLlUgaJpZM4MWake.

extrame avatar Jul 04 '17 02:07 extrame

12.06 显示的1903-04-20T00:00:00Z怎么破

845999248 avatar Feb 22 '19 08:02 845999248

http://www.csindex.com.cn/uploads/file/autofile/perf/950105perf.xls 这个是文件地址,第10列11列有问题

845999248 avatar Feb 22 '19 08:02 845999248

这个问题依旧没有人fix,读取数字类型,依旧被转换成时间字符串

wiyan avatar Dec 11 '21 06:12 wiyan

image 临时这么解决,不知道是不是调用方法有问题,看这里都是转成时间格式的

wiyan avatar Dec 11 '21 07:12 wiyan