# -- coding: utf-8 --
# @Time : 2022/6/20 11:05
import xlrd, xlwt, os
Excel_path = os.path.join(os.path.abspath(__file__), "../data/zentao_login_cookies.xlsx")
class ExcelUtils:
def __init__(self, excel_path=excel_path):
self.excel_path = excel_path
def write_excel(self):
wb = xlwt.Workbook()
sheet = wb.add_sheet('zentao_cookies')
row_list = [["name", "value", "DomAIn", "path"],
['zentaosid', 'l97vmm6ovptiq8c47s6unb2e31', 'xx.107.178.45', '/'],
['theme', 'default', 'xx.107.178.45', '/zentao/www/'],
['device', 'desktop', 'xx.107.178.45', '/zentao/www/'],
['lang', 'zh-cn', 'xx.107.178.45', '/zentao/www/']]
for i in range(0, len(row_list)):
data = row_list[i]
for j in range(0, len(data)):
sheet.write(i, j, data[j])
wb.save(self.excel_path)
def read_excel(self):
wk = xlrd.open_workbook(self.excel_path)
sheet = wk.sheet_by_name("zentao_cookies")
rows = sheet.nrows
cols = sheet.ncols
cookies_list = []
for i in range(cols + 1):
cookie_list = []
for j in range(rows - 1):
cookie_list.Append(sheet.cell_value(i, j))
cookies_list.append(cookie_list)
return cookies_list
def list_to_change_dic(self):
c= []
for i in range(0, 4):
b = []
for j in range (1,5):
a = {self.read_excel()[0][j-1]: self.read_excel()[i+1][j-1]}
b.append(a)
c.append(b)
return c
if __name__ == '__main__':
ecl_util = ExcelUtils()
# ecl_util.write_excel()
# ecl_util.read_excel()
# for i in range(0,4):
# print(ecl_util.list_to_change_dic()[0])
声明:本站部分内容及图片来自互联网,转载是出于传递更多信息之目的,内容观点仅代表作者本人,不构成投资建议。投资者据此操作,风险自担。如有任何标注错误或版权侵犯请与我们联系,我们将及时更正、删除。