How to use the xlrd.xldate_as_tuple function in xlrd

To help you get started, we’ve selected a few xlrd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esitarski / CrossMgr / Excel.py View on Github external
secs += 1.0
						fract = 0.0
					elif fract <= 0.00001:
						fract = 0.0
					
					secs = int(secs)
					if fract:
						value = '{:02d}:{:02d}:{:02d}.{}'.format(
							secs // (60*60), (secs // 60) % 60, secs % 60,
							'{:.20f}'.format(fract)[2:],
						)
					else:
						value = '{:02d}:{:02d}:{:02d}'.format(secs // (60*60), (secs // 60) % 60, secs % 60)
				else:
					try:
						datetuple = xlrd.xldate_as_tuple(value, self.book.datemode)
						validDate = True
					except:
						value = 'UnreadableDate'
						validDate = False
					if validDate:
						if date_as_tuple:
							value = datetuple
						else:
							# time only - no date component
							if datetuple[0] == 0 and datetuple[1] == 0 and  datetuple[2] == 0:
								value = "%02d:%02d:%02d" % datetuple[3:]
							# date only, no time
							elif datetuple[3] == 0 and datetuple[4] == 0 and datetuple[5] == 0:
								value = "%04d/%02d/%02d" % datetuple[:3]
							else: # full date
								value = "%04d/%02d/%02d %02d:%02d:%02d" % datetuple
github jnsebgosselin / gwhat / WHAT / gapfill_weather_gui2.py View on Github external
#==============================================================================                                  
    
    styleDB = db.styleUI()
    
    STANAME = WEATHER.STANAME
            
    nSTA = len(STANAME)
    nVAR = len(WEATHER.VARNAME)
    Ndata_limit = int(365 / 2.)
    
    limitDist = FILLPARAM.limitDist
    limitAlt = FILLPARAM.limitAlt
    
    #--------------------------------------------- TARGET STATION INFO TABLE --
    
    date_start = xldate_as_tuple(FILLPARAM.time_start, 0)
    date_start = '%02d/%02d/%04d' % (WEATHER.DATE_START[TARGET.index, 2],
                                     WEATHER.DATE_START[TARGET.index, 1],
                                     WEATHER.DATE_START[TARGET.index, 0])
                                            
    date_end = xldate_as_tuple(FILLPARAM.time_end, 0)
    date_end = '%02d/%02d/%04d' % (WEATHER.DATE_END[TARGET.index, 2],
                                   WEATHER.DATE_END[TARGET.index, 1],
                                   WEATHER.DATE_END[TARGET.index, 0])
    
    FIELDS = ['Latitude', 'Longitude', 'Altitude', 'Data date start',
              'Data date end']
              
    HEADER = [WEATHER.LAT[TARGET.index],
              WEATHER.LON[TARGET.index],
              WEATHER.ALT[TARGET.index],
              date_start,
github okfn / dataproxy / dataproxy / xlrd / examples / xlrdnameAPIdemo.py View on Github external
def showable_cell_value(celltype, cellvalue, datemode):
    if celltype == xlrd.XL_CELL_DATE:
        try:
            showval = xlrd.xldate_as_tuple(cellvalue, datemode)
        except xlrd.XLDateError:
            e1, e2 = sys.exc_info()[:2]
            showval = "%s:%s" % (e1.__name__, e2)
    elif celltype == xlrd.XL_CELL_ERROR:
        showval = xlrd.error_text_from_code.get(
            cellvalue, '' % cellvalue)
    else:
        showval = cellvalue
    return showval
github occrp-attic / ingestors / ingestors / tabular / xls.py View on Github external
def convert_cell(self, cell, sheet):
        value = cell.value
        try:
            if cell.ctype == 3:
                if value == 0:
                    return None
                year, month, day, hour, minute, second = \
                    xlrd.xldate_as_tuple(value, sheet.book.datemode)
                if (year, month, day) == (0, 0, 0):
                    value = time(hour, minute, second)
                    return value.isoformat()
                else:
                    value = datetime(year, month, day, hour, minute, second)
                    return value.isoformat()
        except Exception:
            pass
        return safe_string(value)
github jnsebgosselin / gwhat / WHAT / gapfill_weather_gui2.py View on Github external
HORDIST = TARGET.HORDIST[index_sort]
    ALTDIFF = TARGET.ALTDIFF[index_sort]
    target_station_index = np.where(TARGET.name==STANAME)[0]
    
    index_start = np.where(TIME == FILLPARAM.time_start)[0][0]
    index_end = np.where(TIME == FILLPARAM.time_end)[0][0]
              
    #----------------------------------------------- Determine filling dates --
    
    fill_date_start = xldate_as_tuple(FILLPARAM.time_start, 0)
    fill_date_start = '%02d/%02d/%04d' % (fill_date_start[2],
                                          fill_date_start[1],
                                          fill_date_start[0])
                                            
    fill_date_end = xldate_as_tuple(FILLPARAM.time_end, 0)
    fill_date_end = '%02d/%02d/%04d' % (fill_date_end[2],
                                        fill_date_end[1],
                                        fill_date_end[0])
                                        
    #---------------------------------------------------- missing data table --
   
    table1 = '''
             <p align="justify">               
               Table 1 : Number of days with missing data from 
               <b>%s</b> to <b>%s</b> for station <b>%s</b>:             
             </p>
             ''' % (fill_date_start, fill_date_end, TARGET.name)
    table1 += '''
              <table align="center" cellspacing="0" cellpadding="3" border="0">
                <tbody><tr></tr></tbody></table>
github cbrownley / data-munging-with-python / excel / 5excel_value_in_set.py View on Github external
with open_workbook(input_file) as workbook:
	#with open(output_file, 'wb') as csv_out_file:
		#filewriter = csv.writer(csv_out_file, delimiter=',')
		worksheet = workbook.sheet_by_name('january_2013')
		for row_index in range(worksheet.nrows):
			output = []
			if row_index &gt; 0:
				cell = xldate_as_tuple(worksheet.cell_value(row_index,4),workbook.datemode)
				cell = str(date(*cell[0:3]).strftime('%m/%d/%Y'))
				if cell in important_dates:
					for col_index in range(worksheet.ncols):
						if col_index &lt; 4:
							cell = worksheet.cell_value(row_index,col_index)
							output.append(cell)
						else:
							cell = xldate_as_tuple(worksheet.cell_value(row_index, col_index),workbook.datemode)
							cell = str(date(*cell[0:3]).strftime('%m/%d/%Y'))
							output.append(cell)
					print output
					#filewriter.writerow(output)
				else:
					pass
			else:
				print worksheet.row_values(row_index)
				#filewriter.writerow(worksheet.row_values(row_index))
github paceaux / xlsx-to-json / xlstojson.py View on Github external
def getRowData(row, columnNames):
	rowData = {}
	counter = 0

	for cell in row:
		# check if it is of date type print in iso format
		if cell.ctype==xlrd.XL_CELL_DATE:
			rowData[columnNames[counter].lower().replace(' ', '_')] = datetime.datetime(*xlrd.xldate_as_tuple(cell.value,0)).isoformat()
		else:
			rowData[columnNames[counter].lower().replace(' ', '_')] = cell.value
		counter +=1

	return rowData
github jnsebgosselin / gwhat / WHAT / gapfill_weather_gui2.py View on Github external
nSTA = len(STANAME)
    nVAR = len(WEATHER.VARNAME)
    Ndata_limit = int(365 / 2.)
    
    limitDist = FILLPARAM.limitDist
    limitAlt = FILLPARAM.limitAlt
    
    #--------------------------------------------- TARGET STATION INFO TABLE --
    
    date_start = xldate_as_tuple(FILLPARAM.time_start, 0)
    date_start = '%02d/%02d/%04d' % (WEATHER.DATE_START[TARGET.index, 2],
                                     WEATHER.DATE_START[TARGET.index, 1],
                                     WEATHER.DATE_START[TARGET.index, 0])
                                            
    date_end = xldate_as_tuple(FILLPARAM.time_end, 0)
    date_end = '%02d/%02d/%04d' % (WEATHER.DATE_END[TARGET.index, 2],
                                   WEATHER.DATE_END[TARGET.index, 1],
                                   WEATHER.DATE_END[TARGET.index, 0])
    
    FIELDS = ['Latitude', 'Longitude', 'Altitude', 'Data date start',
              'Data date end']
              
    HEADER = [WEATHER.LAT[TARGET.index],
              WEATHER.LON[TARGET.index],
              WEATHER.ALT[TARGET.index],
              date_start,
              date_end]
              
    target_info = ''''''
    <table align="left" cellspacing="0" cellpadding="1" border="0"></table>
github skylander86 / lambda-text-extractor / functions / office_extractor / office_extractor.py View on Github external
def xls_to_text(doc_path, event, context):
    book = xlrd.open_workbook(doc_path)
    lines = []
    for sheet in book.sheets():
        lines.append(sheet.name)
        lines.append(u'-------------------------------------------')
        for row in sheet.get_rows():
            row_values = []
            for cell in row:
                if cell.ctype == xlrd.XL_CELL_DATE:
                    d = datetime(*xlrd.xldate_as_tuple(cell.value, book.datemode))
                    row_values.append(d.date() if d.time() == time(0, 0) else d)
                elif cell.ctype == xlrd.XL_CELL_BOOLEAN: row_values.append(bool(cell.value))
                else: row_values.append(cell.value)
            #end for
            lines.append(u'\t|\t'.join(map(lambda s: unicode(s).strip(), row_values)))
    #end for

    return dict(success=True, text=u'\n'.join(lines))
#end def
github PMA-2020 / ppp / pmix / cell.py View on Github external
def parse_datetime(value, datemode):
        """Convert an xlrd cell value to a date time object.

        Args:
            value: The cell value
            datemode (int): The date mode of the Excel workbook
        """
        if datemode is None:
            # set to modern Excel
            datemode = 1
        date_tuple = xlrd.xldate_as_tuple(value, datemode)
        if date_tuple[:3] == (0, 0, 0):
            # must be time only
            value = datetime.time(*date_tuple[3:])
        elif date_tuple[3:] == (0, 0, 0):
            # must be date only
            value = datetime.date(*date_tuple[:3])
        else:
            value = datetime.datetime(*date_tuple)
        return value