Excel file Contents:
Read Excel:
#Coding=utf-8ImportxlrdImportsysreload (SYS) sys.setdefaultencoding ('Utf-8')ImportTracebackclassExcelhandle:defdecode (self, filename, sheetname):Try: FileName= Filename.decode ('Utf-8') SheetName= Sheetname.decode ('Utf-8') exceptException:PrintTraceback.print_exc ()returnfilename, SheetNamedefread_excel (self, filename, sheetname): filename, SheetName=self.decode (filename, sheetname) Rbook=xlrd.open_workbook (filename) sheet=rbook.sheet_by_name (sheetname) rows=sheet.nrows cols=Sheet.ncols all_content= [] forIinchrange (rows): Row_content= [] forJinchRange (cols): CType=Sheet.cell (i, J). CType Cell=Sheet.cell_value (i, J) row_content.append (cell) all_content.append (row_content) Print '['+','. Join ("'"+ str (Element) +"'" forElementinchRow_content) +']' returnall_contentif __name__=='__main__': Eh=excelhandle () filename= R'G:\test\ctype.xls'SheetName='Sheet1'eh.read_excel (filename, sheetname)
Output:
['Plastic Surgery','175.0']['string','the last Knight']['floating Point Type','6.23']['Date','42909.6461574']['Null value',"']
You can see that the numbers are all floating-point output, the date is output as a series of numbers?!!
Python reads Excel, numbers are floating point, and date formats are numeric solutions