Possible Duplicate:
How do I read a date in Excel format in Python?
My date can be among any field in an excel file but when I read it using python xlrd its being read as a float. Is there a way to read all the excel cells as string?
I want to prepare a script to generate a file having all the values in excel file separated by a pipe but this date thing is creating problem.
xldate_as_datetime() function is used to convert excel date/time number to datetime. datetime object. Parameters: This function accepts two parameters that are illustrated below: xldate: This is the specified excel date that will converted into datetime.
Run the following command from the terminal to install the required version of xlrd. After completing the installation process, create a python file with the following script to read the sales. xlsx file using the xlrd module. open_workbook() function is used in the script open the xlsx file for reading.
Excel stores dates as floats. If you want to convert them xlrd
has a function to help you with this: xldate_as_tuple
An exmple:
import datetime, xlrd book = xlrd.open_workbook("myfile.xls") sh = book.sheet_by_index(0) a1 = sh.cell_value(rowx=0, colx=0) a1_as_datetime = datetime.datetime(*xlrd.xldate_as_tuple(a1, book.datemode)) print 'datetime: %s' % a1_as_datetime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With