1、读Excel
导入模块→→→import xlrd
打开Excel文件读取数据→→→data = xlrd.open_workbook('excel.xls')
获取一个工作表→→→
table = data.sheets()[0]#通过索引顺序获取
table = data.sheet_by_index(0)#通过索引顺序获取
table = data.sheet_by_name(u'Sheet1')#通过名称获取
获取整行和整列的值(返回数组)→→→
table.row_values(i)
table.col_values(i)
获取行数和列数→→→ table.nrows和 table.ncols
获取单元格
2、写Excel
导入模块→→→import xlwt
创建workbook→→→ workbook = xlwt.Workbook(encoding = 'utf-8')
创建表→→→worksheet = workbook.add_sheet('My Worksheet')
往单元格内写入内容→→→worksheet.write(0, 0, label = 'Row 0, Column 0 Value')
保存→→→workbook.save('Excel_Workbook.xls')