17.openpyxls处理xls表格

#author: zoe
#date: 2020/5/13
import openpyxl as ox

wb1 = ox.Workbook()

ws1 = wb1.active

ws1[‘A1’] = ‘姓名’

ws1[‘B1’] = ‘price’

ws1[‘C1’] = ‘qunantity’

ws1[‘A2’] = ‘张三’

wb1.save(‘tea.xlsx’)

wb2 = ox.load_workbook(r"E:\date\Python\Project\Day13\tea.xlsx")

wb2.create_sheet(‘backup’,0)

f = wb2.get_sheet_by_name(‘backup’)

ws2 = wb2.get_sheet_by_name(‘Sheet’)
c = ws2[‘A1’]
print(c.value)
a=c.offset(1,0)
print(a.value)

t = ox.cell.cell.get_column_letter(444)

a = ox.cell.cell.column_index_from_string(‘AAA’)

print(a)

for i in ws2[‘A1’:‘C2’]:
for g in i:
print(g.value)

姓名
张三
姓名
price
qunantity
张三
None
None

按行获取数据

import openpyxl as ox

wb2 = ox.load_workbook(r"E:\date\Python\Project\Day13\tea.xlsx")

ws2 = wb2.get_sheet_by_name(‘Sheet’)

rows = ws2.rows
for row in ws2.rows:
for cell in row:
print(cell.value,end=" ")
print()
姓名 price qunantity
张三 None None

你可能感兴趣的:(记录学习历程)