Introduction to Python office 7: xlwt

Time:2021-10-27

Steps to write xlwt to excel

  • Create Workbook
  • Create worksheet
  • Populate sheet contents
  • Save file
1 import xlwt
 2 
 3 # create Workbook
 4 wb=xlwt.Workbook()
 5 # create worksheet
 6 ws=wb.add_sheet("CNY")
 7 # fill data (merge cells)
 8 ws.write_ Merge (0,1,0,5, "2019 currency exchange table")
 9 # write currency data
10 data=((1,1,1,1,1,1),(2,2,2,2,2,2))
11 
12 for i,item in enumerate(data):
13     for j,val in enumerate(item):
14         ws.write(i+2,j,val)
15 
16 # create a second worksheet
17 wsimage=wb.add_sheet("pic")
18 # write picture
19 #wsimage.insert_bitmap(filename="")
20 # save
21 wb.save("2019CNY.xls")