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

    
    
    
    def read_excel():
        # 打开文件
        data = []
        workbook = xlrd.open_workbook(r"C:UsersAdministratorDesktopwork_doccheck.xlsx", "r")
        # 获取所有sheet
        print(workbook.sheet_names() ) # [u'sheet1', u'sheet2']
        sheet2_name = workbook.sheet_names()[0]
    
        # 根据sheet索引或者名称获取sheet内容
        sheet2 = workbook.sheet_by_index(0)  # sheet索引从0开始
        # sheet2 = workbook.sheet_by_name('sheet2')
    
        # sheet的名称,行数,列数
        rows = sheet2.get_rows()
        n = 0
        for i in rows:
            data.append({
                "gid": i[0].value,
                "total":i[3].value,
                "bill":i[4].value
            })
        # print(data[1:])
        # print(type(data[1]["total"]))
        # 获取整行和整列的值(数组)
        # rows = sheet2.row_values(3)  # 获取第四行内容
        # cols_total = sheet2.col_values(3)  # 获取第4列内容
        # cols_bill = sheet2.col_values(4)  # 获取第4列内容
        # for i in
        # print(cols_total)
    
        # # 获取单元格内容
        # print
        # sheet2.cell(1, 0).value.encode('utf-8')
        # print
        # sheet2.cell_value(1, 0).encode('utf-8')
        # print
        # sheet2.row(1)[0].value.encode('utf-8')
    
        # 获取单元格内容的数据类型
        # print(sheet2.cell(1, 0).ctype)
        data = {i["gid"]:i for i in data}
        print(data)
        return data
    
  • 相关阅读:
    canvas
    canvas -矩形
    canvas
    requestAnimationFrame
    flex in css
    让 .vue 支持 atom
    前端应该知道的基础知识汇总
    css伪类总结
    制作滑动门菜单
    页面布局中遇到菱形图片时的处理办法
  • 原文地址:https://www.cnblogs.com/lajiao/p/10020389.html
Copyright © 2011-2022 走看看