Python-manipulating Excel, CSV data files

Source: Internet
Author: User

1. Excel file operation

#-*-coding:utf-8-*-ImportXlrdworkbook= Xlrd.open_workbook ('D:\\workspace\\eclipse-python\\test\\myexcel.xls') SheetName=workbook.sheet_names ()#crawl the names of all sheet pagesPrint 'Myexcel is', sheetname[0],sheetname[1],sheetname[2]#Navigate to Sheet1Worksheet1=workbook.sheet_by_name (U'"Monthly Work"')#traverse all rows in Sheet1 rowNum_rows=worksheet1.nrowsPrintU'total number of rows =', Num_rows forIinchRange (num_rows): Row=worksheet1.row_values (i)PrintU'Gets the first', I,u'rows of data are', row[0],row[1],row[2]#traverse all columns in Sheet1 colnum_cols=Worksheet1.ncolsPrintU'total number of columns =', Num_cols forJinchRange (num_cols): Col=Worksheet1.col_values (j)PrintU'Gets the first', I,u'the data for the column is', col[0],col[1],col[2],col[3],col[4]#traverse all cells in the Sheet1 cell forRowninchRange (num_rows): forColninchRange (num_cols): Cell=Worksheet1.cell_value (ROWN,COLN)PrintCell

Python-manipulating Excel, CSV data files

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.