利用xlrd模块实现Python读取Excel文档

2015-07-27 0 735
利用xlrd模块实现Python读取Excel文档
# -*- coding: cp936 -*-
#python读取excel
import xlrd

def main():
    xls=xlrd.open_workbook("d:\\11.xls")
    try:
        mysheet=xls.sheet_by_name("Sheet1")#找到名为Sheet1的工作表。区分大小写
    except:
        print("没有此工作表")
        return

    print("共有 %d 行, %d 列。"%(mysheet.nrows,mysheet.ncols))

#将内容逐个打印出来:
    
    for row in range(0,mysheet.nrows):
        for col in range(0,mysheet.ncols):
            if mysheet.cell(row,col).value != None:
              temp=mysheet.cell(row,col).value#将单元格里面的数据赋给temp
              print(type(temp))#依次打印出excel单元格里面的数据类型
              print(temp)#依次打印出excel单元格里面的内容
if __name__=='__main__':
    main()

遇见资源网 python 利用xlrd模块实现Python读取Excel文档 http://www.ox520.com/15661.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务