python之Excel操作

时间:2021-06-25 22:09:25
#coding:utf-8
__author__ = 'similarface' import xlrd book=xlrd.open_workbook('/Users/similarface/Downloads/0808-10个ET/0808-10个ET.xlsx')
#遍历所有的sheets
for sheet in book.sheets():
print(sheet.name)
#print sheet book = xlrd.open_workbook('/Users/similarface/Downloads/0808-10个ET/0808-10个ET.xlsx')
#获取指定的sheet
sheet = book.sheet_by_name('Sheet1')
#获取sheet的行数
print sheet.nrows
#遍历sheet的所有行号
for i in range(sheet.nrows):
print i
#遍历sheet的所有行
for i in range(sheet.nrows):
print sheet.row_values(i) #遍历所以的行,
for i in range(sheet.nrows):
row=sheet.row_values(i)
#遍历行的所有列的值
for cell in row:
print cell