Python reads Excel, numbers are floating point types, date formats are numeric solutions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.