Python xlrd xlwt 读取写入Excel.

import xlrd
import xlwt


#读取
xlrd.Book.encoding = "gbk"
wb = xlrd.open_workbook(filename='sfp.xlsx', )

table = wb.sheets()[3]
nrows = table.nrows

for k in range(1, nrows ):
    print(table1.row_values(k))



#写入

workbook = xlwt.Workbook(encoding='gbk')
sheet = workbook.add_sheet("Miss")
for i in range(0, len(row)):
    sheet.write(0, i, row[i])
style = xlwt.easyxf('align: wrap on')
sheet.col(0).width = 256 * 20
sheet.col(1).width = 256 * 30
sheet.col(2).width = 256 * 30

num = 1
for item in count_list :
    sheet.write(num, 0, item[0], style)
    sheet.write(num, 1, item[1], style)
    sheet.write(num, 2, item[2], style)
    num += 1


workbook.save('xxxx.xls')
posted @ 2018-12-19 17:29 MAU 阅读(...) 评论(...) 编辑 收藏
Life will always knock us down, but we can choose whether to stand back up, then keep fighting. 生活会把我们打趴下,但我们可以选择重新站起来,继续奋斗。