How to use ``xlrd.xldate_as_tuple()``

后端 未结 5 1206
情话喂你
情话喂你 2020-12-03 05:05

I am not quite sure how to use the following function:

xlrd.xldate_as_tuple

for the following data

xldate:39274.0
xldate:39         


        
5条回答
  •  情话喂你
    2020-12-03 05:26

    import datetime as dt
    import xlrd
    
    log_dir = 'C:\\Users\\'
    infile = 'myfile.xls'
    book = xlrd.open_workbook(log_dir+infile)
    sheet1 = book.sheet_by_index(0)
    date_column_idx = 1
    
    ## iterate through the sheet to locate the date columns
    for rownum in range(sheet1.nrows):
        rows = sheet1.row_values(rownum)
    
        ## check if the cell is a date; continue otherwise
        if sheet1.cell(rownum, date_column_idx).ctype != 3 :
            continue
    
        install_dt_tuple = xlrd.xldate_as_tuple((rows[date_column_idx ]), book.datemode)
    
        ## the "*date_tuple" will automatically unpack the tuple. Thanks mfitzp :-)
        date = dt.datetime(*date_tuple)
    

提交回复
热议问题