Python:把乘法口诀表写入excel表格(openpyxl) - Go语言中文社区

Python:把乘法口诀表写入excel表格(openpyxl)


import openpyxl
from openpyxl.styles import Font
from openpyxl.utils import get_column_letter
wb=openpyxl.Workbook()
sheet=wb.active
fontGoal1=Font(name='Microsoft YaHei',bold='True')
print('Please type the number of formula:')
i=int(input())
#sheet['B1':get_column_letter(i+1)+str(1)].font=fontGoal1
for rowOfUtilGoal in sheet['B1':get_column_letter(i+1)+str(1)]: #加粗每列乘数字体
    for UtilGoal in rowOfUtilGoal:
        UtilGoal.font=fontGoal1
#sheet['A2':A+str(i+1)].font=fontGoal1
for rowOfUtilGoal in sheet['A2':'A'+str(i+1)]: #加粗每行乘数的字体
    for UtilGoal in rowOfUtilGoal:
        UtilGoal.font=fontGoal1
#for rowOfGoal in sheet['B1:get_column_letter(i+1)+str(1)']:
    #rowOfGoal.value=
for row in range(2,i+2):       #赋值给乘法口诀表的行
    sheet[get_column_letter(row)+str(1)].value=row-1
for row in range(2,i+2):       #赋值给乘法口诀表的列
    sheet['A'+str(row)].value=row-1
for rowOfUtilGoal in sheet['B2':get_column_letter(i+1)+str(i+1)]:  #赋值乘法公式
    for UtilGoal in rowOfUtilGoal:
        #UtilGoal.value='='+get_column_letter(UtilGoal.row)+str(UtilGoal.column-(UtilGoal.column-1))+'*'+get_column_letter(UtilGoal.row-1)+str(UtilGoal.column)
         UtilGoal.value='='+'A'+str(UtilGoal.row)+'*'+get_column_letter(UtilGoal.column)+str(1)
wb.save('multiplication.xlsx')

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/z594934262/article/details/104538387
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 23:17:01
  • 阅读 ( 959 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢