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')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM