import os
from openpyxl import load_workbook
excel_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"cla.xlsx")
wb = load_workbook(excel_path)
sh = wb["Sheet1"]
print(sh.cell(3,3).value)
print(sh.cell(3,4).value)
sh.cell(1,1).value = "id "
sh.cell(3,3).value ="python"
wb.save(excel_path)
new_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"new_cases.xlsx")
wb.save(new_path)
print(sh.max_row)
print(sh.max_column)
for row in list(sh.values):
print(row)
for values in all_values[1:]:
print(keys,values)
cases_list = []
all_values = list(sh.values)
keys = all_values[0]
for values in all_values[1:]:
case = dict(zip(keys,values))
print(case)
cases_list.append(case)
new1 = {"性别","姓名","年龄","身高"}
new2 = {"男","python菜鸟","21","175"}
res = list(zip(new1,new2))
print(res)
res1 = dict(zip(new1,new2))
print(res1)
|