ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python28 excel读取模块xlrd

2019-02-02 11:42:28  阅读:389  来源: 互联网

标签:sheet excel nrows print sheet1 python28 xlrd col row


安装:

pip install xlrd

 

简单使用:

import xlrd

book = xlrd.open_workbook(r'C:\Users\dinghanhua\Desktop\yqqapi.xlsx') # 打开excel
print("the number of sheets:",book.nsheets) # sheet数量
print("sheet_names:",book.sheet_names()) # sheetname列表

sheet1 = book.sheet_by_index(0) # 通过索引取sheet
print(sheet1.name,sheet1.nrows,sheet1.ncols) #sheet名称、行数、列数
print(sheet1.cell(0,0).value) #cell值
print(sheet1.cell_value(0,1)) #cell值

sheet2 = book.sheet_by_name("sheet2") # 通过sheetname取sheet
print(sheet2.name,sheet2.nrows,sheet2.ncols)

# 获取sheet所有的数据
for row in range(sheet1.nrows):
    for col in range(sheet1.ncols):
        print(sheet1.cell_value(row,col),end='\t')
    print('\n')

print(sheet1.col_values(0,1,sheet1.nrows)) # 获取第一列,第2行的所有值

print(sheet1.row(1)) # 获取第二行的值

for col in range(sheet1.ncols): # 按列获取值,每列是list
    print(sheet1.col_values(col,0,sheet1.nrows))

for row in range(sheet1.nrows): # 按行获取值;每行都是list
    print(sheet1.row_values(row,0,sheet1.ncols))

 

 

the end!

 

标签:sheet,excel,nrows,print,sheet1,python28,xlrd,col,row
来源: https://www.cnblogs.com/dinghanhua/p/10348076.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有