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')
相關文章
相關標籤/搜索