一、使用介绍

     1、导入模块

          import xlrd

     2、打开Excel文件读取数据

         xls_file = r'C:/Users/Desktop/1_1.xlsx'

         book=xlrd.open_workbook(xls_file) #得到Excel文件的book对象,实例化对象

   

     3、使用技巧

        获取一个工作表

        table = book.sheets()[0]          #通过索引顺序获取

        table = book.sheet_by_index(0) #通过索引顺序获取

        table = book.sheet_by_name(u'Sheet1')#通过名称获取

        获取整行和整列的值(数组) 

         table.row_values(i)

         table.col_values(i)

        获取行数和列数  

        nrows = table.nrows

        ncols = table.ncols     

        循环行列表数据

        for i in range(nrows ):

        print table.row_values(i)

 

        单元格

        cell_A1 = table.cell(0,0).value

        cell_C4 = table.cell(2,3).value

       使用行列索引

       cell_A1 = table.row(0)[0].valu

       cell_A2 = table.col(1)[0].value

 python操作Excel读--使用xlrd

相关文章:

  • 2021-10-29
  • 2021-11-16
  • 2021-07-28
  • 2022-01-04
  • 2021-12-16
  • 2021-05-25
猜你喜欢
  • 2021-06-11
  • 2021-10-11
  • 2021-04-02
  • 2022-01-13
  • 2021-12-22
  • 2021-11-05
  • 2021-12-22
相关资源
相似解决方案