希望表格里面字体不一样,用下拉自动填充做不到,openpyxl可以
from openpyxl import Workbook, load_workbook
from openpyxl.styles import Font
from random import choice, randint
book = ('sdf.xlsx')
wb = load_workbook(book)
sheet1 = wb.worksheets[0]
fon = ['字体1','字体2']
def change(obj):
obj.font = Font(size=randint(14,17), name=choice(fon))
i = randint(0,5)
if (i == 0):
obj.value =' ' + obj.value
elif(i == 1):
obj.value = obj.value + ' '
else:
obj.value = obj.value
#主要处理代码
word = ['1','2','3']
for i in range(8,46):
si = sheet1['G'+str(i)]
write(si, word[0])
change(si)
wb.save(book)
8到46行是需要填写的范围,G是列号,si是单元格对象
change方法会随机更改字符大小和字体
至于有什么用,看使用者
字体更改软件fontcreater 自己摸索出来的方法: