python3读取execl文件进行redis批量插入数据操作

#!/usr/bin/python3.9
# -*- coding: utf-8 -*-
import openpyxl
import os
import redis
rd=redis.Redis(host='xx.xx.xx.xx', port='6379',password="xxx" db=0)
print(rd.hgetall('gray_user_list'))
print('当前工作目录 :')
print(os.getcwd(), ' ')
wb=openpyxl.load_workbook(filename=r'company_id.xlsx')
sheet=wb['1']
row=sheet.max_row
print('取得活动工作表 :')
active_sheet = wb.active
print('表名 --> ' + active_sheet.title, ' ')
print('表名%s总共行数为%s'%(active_sheet,row))
#cell=active_sheet['A1']
#print(cell.value)
data_list=[]
for row in sheet.rows:
    for cell in row:
        value=cell.value
        rd.hset("gray_user_list",value,"true")

原文地址:https://www.cnblogs.com/wudongyu/p/14926829.html