1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import qrcode
import openpyxl
from openpyxl.drawing.image import Image

def open_cell(num):
cell = sheet["A" + num]
return cell.value

def gen_image(text,name):
img = qrcode.make(text)
with open(name,"wb") as f:
img.save(f)

def write_img(img_name,position):
imgsize = (720/12,720/12)
img = Image(img_name)
img.width,img.height = imgsize
sheet.add_image(img,position)

if __name__ == "__main__":
wb_name = "text.xlsx"
wb = openpyxl.load_workbook(wb_name)
sheet = wb.worksheets[0]
if not os.path.exists("qrcode"):
os.mkdir("qrcode")

for i in range(1,10):
test = open_cell(str(i))
test_png_name = "qrcode/" + "A" + str(i) + ".png"
paste = "B" + str(i)
gen_image(test,test_png_name)
write_img(test_png_name,paste)

wb.save(wb_name)