#python读取excelfrom openpyxl import load_workbookwb = load_workbook('test.xlsx')print(wb.sheetnames)
from openpyxl import load_workbookwb = load_workbook('test.xlsx')sheet = wb.get_sheet_by_name('Sheet1')print(sheet['A'])#列表A的所有数据 >>>(, | , | , | , | , | , | , | , | , | ) |
print(sheet['4'])#列表第四行的所有内容 >>>(, | , | , | , | ) |
print(sheet['C4'].value) >>>哎哟哇
for i in sheet['C']: print(i.value)
>>>c1
c2 c3 哎哟哇 c5 c6 c7 c8 c9 c10
#python 写入excelfrom openpyxl import Workbookwb = Workbook()sheet = wb.activesheet.title = 'New sheet'#定义sheet的标题,下面的sheet名字sheet['C3'] = 'hello'#C列,第三行,写入hellofor i in range(10): sheet['A%d' %(i+1)].value = i+1#循环遍历0到9,然后i+1 就是1到10,这句话表示A1-A10,写入1-10sheet['E1'].value = '=SUM(A:A)'#在E1写入A列所有数据的和wb.save('保存一个新的excel.xlsx')#保存到一个新的excel