Pip Install xlrd XLWT
Write Excel
#coding =utf-8
Import XLWT
Workbook = xlwt. Workbook (encoding= ' utf-8 ')
Booksheet = Workbook.add_sheet (' Sheet 1 ', cell_overwrite_ok=true)
Workbook.add_sheet (' Sheet 2 ')
DATA = (' study number ', ' name ', ' age ', ' gender ', ' score '),
(1001, ' AAAA ', at 98, ' male '),
(1002, ' BBBB ', +, ' female ', 90),
(1003, ' CCCC ', ' 100 ', ' female '),
(1004, ' DDDD ', ' a ', ' female ', 86),
(1005, ' eeee ', +, ' female ', 88),)
For I, row in enumerate (DATA):
Forj, col in Enumerate (row):
Booksheet.write (i, J, Col)
Workbook.save (' Chenji.xls ')
Chenji.xls Display
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/76/86/wKioL1ZVdcOiBNgSAAAsTl4mP4g701.png "title=" Chenji.png "alt=" Wkiol1zvdcoibngsaaastl4mp4g701.png "/>
Read Excel
Read Excel
Get a file
Workbook = Xlrd.open_workbook (' transcript. xls ')
Get the number of forms in a file
Workbook.nsheets
Get a form
Workbook.sheets () [i],
Workbook.sheet_by_index (i)
Workbook.sheet_by_name (U ' Sheet1 ')
Get row, number of columns
Sheet.nrows, Sheet.ncols
Get the entire row, column data
Sheet.row (i), Sheet.col (j)
Get a cell data
Sheet.cell (i, j). Value
Sheet.row (i) [J].value
Sheet.col (j) [I].value
#coding =utf-8
Import xlrd
Workbook = Xlrd.open_workbook (' Chenji.xls ')
Print "There is {} sheets in the workbook". Format (workbook.nsheets)
For Booksheet in Workbook.sheets ():
Print Booksheet.name
For row in Xrange (booksheet.nrows):
For Col in Xrange (booksheet.ncols):
Print xlrd.cellname (row, col) #打印列名A1, B2 ...
Print Booksheet.cell (row, col). Value #打印单元格的值
This article is from the DBA Sky blog, so be sure to keep this source http://9425473.blog.51cto.com/9415473/1716804
Traverse a tuple to write Excel, read an Excel file