# #写excel # import xlwt # # book = xlwt.Workbook() # sheet = book.add_sheet('xuesheng') # all_data = [ # ['id','name','sex','phone','country'], # ['1','xiaoming','男',13111111111,'china'], # ['2','xiaoming','男',13111111111,'china'], # ['3','xiaoming','男',13111111111,'china'], # ['4','xiaoming','男',13111111111,'china'], # ['5','xiaoming','男',13111111111,'china'], # ['6','xiaoming','男',13111111111,'china'], # ] # # line = 0 #行号 # # for data in all_data: # # sheet.write(line,0,data[0]) # # sheet.write(line, 1, data[1]) # # sheet.write(line, 2, data[2]) # # sheet.write(line, 3, data[3]) # # sheet.write(line, 4, data[4]) # # line+=1 # # book.save('s.xls') # # line = 0 #行号 # for data in all_data: # #['id','name','sex','phone','country'] # #['1','xiaoming','男',13111111111,'china'] # col = 0 # 列号 # for d in data: # # id name sex # sheet.write(line, col, d) # col +=1 # line+=1 # book.save('1.xls') ###################### # import string # case = list(string.ascii_uppercase) # #print('a=>0') # index = 0 # for c in case: # print('%s => %s'%(c,index)) ####### enumerate自动加1,不需要手动加1 # import string # case = list(string.ascii_uppercase) # #print('a=>0') # index = 0 # for index,c in enumerate(case,2):#参数中设置2,则默认从2开始 # print('%s => %s'%(c,index)) ##############优化 import xlwt book = xlwt.Workbook() sheet = book.add_sheet('xuesheng') all_data = [ ['id','name','sex','phone','country'], ['1','xiaoming','男',13111111111,'china'], ['2','xiaoming','男',13111111111,'china'], ['3','xiaoming','男',13111111111,'china'], ['4','xiaoming','男',13111111111,'china'], ['5','xiaoming','男',13111111111,'china'], ['6','xiaoming','男',13111111111,'china'], ] #enumerate() 自动加1 print(type(all_data)) for line,data in enumerate(all_data): for col,d in enumerate(data): sheet.write(line,col,d) book.save('s2.xls')