zoukankan      html  css  js  c++  java
  • python脚本 读取excel格式文件 并进行处理的方法

    一.安装xlrd模块

    pip install xlrd

    二.读取excel文件

    try:
        excel_obj = xlrd.open_workbook("文件路径")
    except Exception as e:
        print(e)

    三.读取工作表内容

    tables = excel_obj.nsheets # 获取文件中工作表的数目
    all_table_dict = {}
    for i in range(0, tables):
      table
    = data.sheet_by_index(i) # 根据工作表的索引获取一个工作表对象
      total_nows = table.nrows # 获取这个工作表的总行数
      total_ncols = table.ncols # 获取这个工作表的总列数
      table_header = table.row_values(0) # 获取表头行数据
      print(table_header)
      one_table_list = []
      for one_row in range(1, total_rows): 从第二行开始循环取出每一行的数据
        row = table.row_values(one_row) # 获取一行数据
        if row:
          row_object = {}
          for col in range(0, total_ncols): # 循环出一行数据里的每列数据
            key = table_header[col] # 当前列的表头名称
            row_object[key] = row[col] # 给相应的表头名称进行赋值
          one_table_list.append(row_object)
      all_table_dict["table"+i] = one_tale_list
  • 相关阅读:
    WEB上传大文件
    Java+超大文件上传
    php+文件夹上传
    php上传视频大文件
    每一个程序猿需掌握的20个代码命名小贴士
    Mysql整数运算NULL值处理注意点
    拓展欧几里得模板
    bzoj 1088 简单dfs
    决策树
    进程-IPC 管道 (一)
  • 原文地址:https://www.cnblogs.com/lowmanisbusy/p/9381253.html
Copyright © 2011-2022 走看看