首页 > 学院 > 开发设计 > 正文

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

2019-11-14 17:23:16
字体:
来源:转载
供稿:网友
# -*- coding: cp936 -*-#python读取Excelimport xlrddef 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()

 需要下载xlrd模块:https://pypi.python.org/pypi/xlrd/0.8.0


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表