2019的第一天,忘记昨日之事,迎接新的明天。
excel表格文件办公中常用,如通过Python操作这些数据需导入并有序读取这些数据
特随笔,供以后查阅
代码如下:
import xlrd
# file = '1.xls'
# # def read_excel():
# wb = xlrd.open_workbook(filename=file)#打开文件
# # print(wb.sheet_names())#获取所有表格名字
# print(wb....)
# sheet1 = wb.sheet_by_index(0)#通过索引获取表格
# sheet2 = wb.sheet_by_name('无爱')#通过名字获取表格
# print(sheet2)
# print(sheet1.name,sheet1.nrows,sheet1.ncols)
# rows = sheet1.row_values(2)#获取行内容
# cols = sheet1.col_values(3)#获取列内容
# print(rows)
# print(cols)
# print(sheet1.cell(1,0).value)#获取表格里的内容,三种方式
# print(sheet1.cell_value(1,0))
# print(sheet1.row(1)[0].value)
boos= xlrd.open_workbook('1.xls')
sheet = boos.sheet_by_index(0)
for user in range(1, sheet.nrows):
print(sheet.row_values(user, 0, sheet.ncols))