title: Python Excel 批量生成二维码
date: 2021-11-06 10:14:19
tags: [python, excel, 二维码]
网上制作二维码的手段单一,不符合我的需求,故“自己动手丰衣足食”。
通过 pipreqs 生成 requirements.txt(会有些是不需要的)
pip freeze>requirements.txt
requirements.txt
attrs==19.3.0
Automat==20.2.0
beautifulsoup4==4.8.2
bs4==0.0.1
certifi==2019.3.9
cffi==1.14.0
chardet==3.0.4
click==7.1.1
constantly==15.1.0
cryptography==2.9
cssselect==1.1.0
cycler==0.10.0
defusedxml==0.6.0
docopt==0.6.2
fasttext==0.9.2
Flask==1.1.2
Flask-Login==0.5.0
hyperlink==19.0.0
idna==2.8
incremental==17.5.0
itsdangerous==1.1.0
Jinja2==2.11.2
json5==0.9.4
kiwisolver==1.1.0
lxml==4.5.0
MarkupSafe==1.1.1
matplotlib==3.1.2
numpy==1.18.1
parsel==1.5.2
Pillow==7.0.0
pipenv==2018.11.26
pipreqs==0.4.10
Protego==0.1.16
pyasn1==0.4.8
pyasn1-modules==0.2.8
pybind11==2.5.0
pycparser==2.20
pycurl==7.43.0.5
PyDispatcher==2.0.5
PyHamcrest==2.0.2
pymongo==3.10.1
PyMySQL==0.9.3
pyOpenSSL==19.1.0
pyparsing==2.4.6
pyquery==1.4.1
pyspider==0.3.10
python-dateutil==2.8.1
PyYAML==5.3.1
queuelib==1.5.0
requests==2.22.0
Scrapy==2.0.1
selenium==3.141.0
service-identity==18.1.0
six==1.13.0
soupsieve==2.0
tblib==1.6.0
tesserocr==2.4.0
tornado==4.5.3
Twisted==20.3.0
u-msgpack-python==2.5.2
urllib3==1.25.7
virtualenv==16.5.0
virtualenv-clone==0.5.3
w3lib==1.21.0
Werkzeug==1.0.1
wordcloud==1.6.0
WsgiDAV==3.0.3
xlwt==1.3.0
yarg==0.1.9
zope.interface==5.1.0
import pandas as pd
import qrcode
# excel 文件名
file_name = 'door.xlsx'
# excel 子表名或序号(从 0 开始)
sheet_name = 'Sheet1' # sheet_name = 0
# 首行位置(从 0 开始)
header = 0
# 读取 excel
sheet = pd.read_excel(file_name, sheet_name, header)
# 读取 excel 中列名为 col_name 的列
col_name = '物业'
name_values = sheet[col_name]
# 生成二维码
for name in name_values:
qr = qrcode.QRCode(
version=3,
error_correction=qrcode.constants.ERROR_CORRECT_Q,
box_size=10,
border=4
)
qr.add_data(name)
qr.make(fit=True)
img = qr.make_image(fill_color='black', back_color='white')
img_name = col_name + '/' + name + '.png'
img.save(img_name)