我想读取excel表格中的单元格(1,1)值,它是21-08-18
.格式的日期。我正在使用 python 包xlrd
读取值,它返回浮点值 ex。喜欢 4567.0
book = xlrd.open_workbook(path)
compSheet = book.sheet_by_name("sheet_name")
cell_value = compSheet.cell_value(1, 1)
如何知道单元的数据类型读取值无论是之前date
或string
或float
或等。
您可以获取单元格的类型以查看它是否为日期并将其与xlrd 的单元格对象定义进行比较(或直接将其与该表中看到的数字进行比较,因为 cell.ctype 只返回一个数字)。
book = xlrd.open_workbook(path)
compSheet = book.sheet_by_name("sheet_name")
cell = compSheet.cell(1,1)
if cell.ctype is xlrd.XL_CELL_DATE:
print "Cell 1,1 is a date!"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句