首页 > 其他 > 详细

乘法表

时间:2018-08-29 12:49:06      阅读:155      评论:0      收藏:0      [点我收藏+]
 1 import openpyxl
 2 from openpyxl.styles import Font
 3 
 4 wb = openpyxl.Workbook()
 5 sheet = wb.get_active_sheet()
 6 
 7 font = Font(size=20,bold=True)  # 粗体
 8 
 9 # 生成乘法表
10 num = int(input(请输入最大数字:))
11 nums_row = list(range(1, num+1))
12 nums_column = list(range(1, num+1))
13 nums_result = []
14 
15 for num_row in nums_row:
16     def f(x):
17         return num_row * x
18     nums_result.append(list(map(f, nums_column)))  # map(f(), nums_column)报错
19 
20 #  设置表头格式,添加表头内容
21 for i in range(2, num+2):
22     sheet.cell(row=1, column=i).font = font
23     sheet.cell(row=1, column=i).value = nums_column[i-2]
24     sheet.cell(row=i, column=1).font = font
25     sheet.cell(row=i, column=1).value = nums_column[i-2]
26 
27 # 填充乘法表
28 for i in range(2, num+2):
29     for j in range(2, num+2):
30         sheet.cell(row=i, column=j).value = nums_result[i-2][j-2]
31 
32 # 保存xlsx
33 wb.save(multi_plication_table.xlsx)

 

乘法表

原文:https://www.cnblogs.com/jiangchengzi93812/p/9552400.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!