使用xlsxwriter模块
```
import xlsxwriter
import pymysql.cursors
connect = pymysql.Connect(
host='localhost',
port=3306,
user='root',
passwd='admin123',
db='enterprise',
charset='utf8'
)
try:
wb = xlsxwriter.Workbook('enterprise_6.xlsx')
ws = wb.add_worksheet('企业信息')
header = ['ID', '名称', '电话(图片)', '电话', '联系人', '邮箱', '网址', '地址']
for index, h in enumerate(header):
ws.write(0, index, h)
with connect.cursor() as cursor:
sql = 'select `id`,`name`,`phone_pic`,`phone`,`linkman`,`email`,`weburl`,`address` from `ep_company_info` where `id`<=12000 and `id`>10000'
data = cursor.execute(sql)
data_ = cursor.fetchall()
j = 1
for i, v in enumerate(data_):
ws.write(j, 0, v[0])
ws.write(j, 1, v[1])
if v[2] == '':
ws.write(j, 2, v[2])
else:
ws.insert_image(j, 2, './company/' + str(v[2]))
ws.write(j, 3, v[3])
ws.write(j, 4, v[4])
ws.write(j, 5, v[5])
# 网址
ws.write_url(j, 6, v[6])
ws.write(j, 7, v[7])
j += 1
finally:
wb.close()
print('完成')
```