zoukankan      html  css  js  c++  java
  • python

    from openpyxl import load_workbook
    
    wb = load_workbook(r'C:UsersadminDesktop数据筛选.xlsx')
    
    # print(wb.get_sheet_names())
    
    # 数据表1
    sheet = wb.get_sheet_by_name('Sheet1')
    # print(a1_sheet)
    
    # b1 = a1_sheet['B1']
    # 列数,行数,数值
    # print(b1.column,b1.row,b1.value)
    
    # c1 = a1_sheet.cell(row=1,column=3)
    # print(c1.value)
    
    # 最大行,最大列
    # print(sheet.max_row)
    # print(sheet.max_column)
    
    # 所有行
    # for row in sheet.rows:
    #     for cell in row:
    #         print(cell.value)
    
    # 所有列
    # for column in sheet.columns:
    #     for cell in column:
    #         print(cell.value)
    
    # 哪一行
    # for cell in list(sheet.rows)[0]:
    #     print(cell.value)
    
    # 哪一列
    for cell in list(sheet.columns)[3]:
        try:
            a1,a2,a3 = cell.value.split(' ')
            print(a1,a2,a3)
        except Exception as e:
            pass
    
    
    # 获取一个矩阵
    # for i in range(1, 4):
    #     for j in range(1, 4):
    #         print(sheet.cell(row=i, column=j).value)
    
    # for row_cell in sheet['A1':'B3']:
    #     for cell in row_cell:
    #         print(cell)
    
    
    # from openpyxl.utils import get_column_letter, column_index_from_string
    # # 根据列的数字返回字母
    # print(get_column_letter(2)) # B
    # # 根据字母返回列的数字
    # print(column_index_from_string('D')) # 4
    
    # --------------------------------------------------------------
    
    # 写入数据
    
    #
    sheet['D14'] = a1
    from openpyxl import Workbook
    # 创建一个新的表
    # wb = Workbook()
    
    # 创建一个新的工作区 # wb.create_sheet(
    'Data', index=1) # wb.save(r'C:UsersadminDesktop数据筛选2.xlsx') # wb.close() # # 删除某个工作表 # wb.remove(sheet) # del wb[sheet]

    相关文章:

    https://www.cnblogs.com/276815076/p/8028127.html

  • 相关阅读:
    记一次vue.js用 http.post 前端传json到后台用javabean接收的坑
    springboot1.5.x 测试sample
    sqlserver 查询表缺失索引
    Docker swarm上线的一些问题
    数据库日志文件压缩
    Docker 挂载
    单播广播和多播
    导入数据库表后某些字段的精度为0
    Source Qualifiter组件中Sql Query属性的脚本返回结果集的列数大于组件定义的数量
    distinct和order by冲突
  • 原文地址:https://www.cnblogs.com/Anec/p/10657998.html
Copyright © 2011-2022 走看看