zoukankan      html  css  js  c++  java
  • 读取excel数据

     1 import xlrd
     2 #导入Excel库
     3 
     4 class xls:
     5 
     6     def __init__(self,url,row,col,num = 0):
     7         self.url = url
     8         self.row = row
     9         self.col = col
    10         self.num = num
    11 
    12     def read_xls(self):
    13         excelfile = xlrd.open_workbook(self.url)
    14         # 获取文件位置
    15         sheet_file = excelfile.sheet_names()
    16         # 获取所有工作表名,得到一个list列表
    17         # print(type(sheet_file))
    18         sheet_name = sheet_file[self.num]
    19         # 获取指定工作表名称
    20         sheet = excelfile.sheet_by_name(sheet_name)
    21         # 获取工作表对象
    22         # sheet.name,sheet.nrows,sheet.ncols
    23         # 工作表名称、行数、列数
    24         #col_sheet = sheet.col(self.col)
    25         # 获取工作表指定列内容,得到list列表
    26         #row_sheet = sheet.row(self.row)
    27         # 获取工作表指定行内容,得到list列表
    28         value_sheet = sheet.cell(self.col-1,self.row-1).value
    29         # 获取指定单元格内容
    30 
    31         return value_sheet
    32 
    33 a = xls(r"C:wbw	est.xls",1,2,)
    34 print(a.read_xls())
    35 
    36 #需传入文件路径、列数、行数、工作表角标(默认第一个)
  • 相关阅读:
    把字符串输入到表格里
    x 的 x 次方等于10,求 x
    java 中 二进制串与浮点数的相互转化
    堆栈 Objective-C NSString copy strong
    c一些学习过程中突然错过的细节
    视图控制器
    名词从句
    FastDFS
    Python
    http 提交表单数据
  • 原文地址:https://www.cnblogs.com/wbw-test/p/11506980.html
Copyright © 2011-2022 走看看