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