![](/img/trans.png)
[英]How can I Define a function that offers a data and returns True if the data type is string, etc.?
[英]How to determine the excel cell value type(data type such as date, string, float etc.)
我想讀取Excel工作表中的cell(1,1)值,它是21-08-18
格式的21-08-18
。 我正在使用python包xlrd
讀取值,它返回float值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!"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.