from openpyxl import load_workbook
wb=load_workbook('op.xlsx')
‘’’
工作簿的属性与方法:
sheetnames=wb.get_sheet_names()
print(sheetnames)
wb.get_sheet_by_name(sheetnames[0])
‘’’
sheet=wb[‘Sheet’]
sheet=wb.get_sheet_by_name('Sheet')
#sheet.values 表所有单元格数据组成的对象
values=sheet.values
data=list(values)
print(data)
firstColumn=[each[0] for each in data]
print(firstColumn)
print(sheet['A1'].value)
rows=len(data)
c_col=[]
for i in range(1,rows+1):
c_col.append(sheet[f'c{i}'].value)
print(c_col)
print([sheet[f'b{i}'].value for i in range(1,len(list(sheet.values))+1)])
print([each[1] for each in list(sheet.values)])
english=wb.create_sheet('英语',3)
english.append(['no can no bb'])
wb.save('op.xlsx')