import xlwt my_workbook = xlwt.Workbook(encoding='utf-8') my_sheet1 = my_workbook.add_sheet('sheet1') for i in range(0, 9): # i:行号 for j in range(0, i+1): # j:列号 # 写入数据时注意:因为行号列号从0开始,而99乘法表从1开始,需要+1 my_sheet1.write(i, j, '%d * %d = %d' %(i+1, j+1, (i+1)*(j+1))) my_workbook.save('99multiple.xls')
结果: