import xlwt wookbook = xlwt.Workbook(encoding="utf-8") #创建workbook对象 worksheet = wookbook.add_sheet('sheet1') #创建工作表 # worksheet.write(0,0,"hello") #向EXCEL里写入数据,(0,0,"hello") 指第1行,第1列,要写入的内容 # 方法一: ''' for num2 in range(1,10) : for num1 in range(1,10) : mul = num1 * num2 print("%d * %d = %d "%(num1,num2,mul),end=" ") worksheet.write(num2-1,num1-1,"%d * %d = %d "%(num1,num2,mul)) if num1 ==num2 : print("") break wookbook.save('九九口决.xls') # 保存数据表 ''' # 方法二: for i in range(0,9): for j in range(0,i+1): print("%d * %d = %d "%(j+1,i+1,(j+1)*(i+1)),end=" ") worksheet.write(i, j, "%d * %d = %d " % (j + 1, i + 1, (j + 1) * (i + 1))) # if i == j: # print("") # break wookbook.save('九九口决.xls')