导航

 

 

 

import openpyxl
def excelReadAndWrite():
    data = openpyxl.load_workbook(r'C:\Users\89349\Desktop\MonitoringLogging2020082.xlsx')
    print(data.defined_names.definedName) # 输出工作页索引范围
    print(data.sheetnames) # 输出所有工作页的名称
    # 取第一张表
    sheetnames = data.sheetnames
    # table = data.get_sheet_by_name(sheetnames[0])
    table = data['test']
    table = data.active
    print(table.title) # 输出表名
    nrows = table.max_row # 获得行数
    ncolumns = table.max_column # 获得列数
    values = ['A','B','C']
    for value in values:
        print(nrows)
        table.cell(nrows+1,1).value = value
        nrows = nrows + 1
    data.save(r'C:\Users\89349\Desktop\MonitoringLogging2020082.xlsx')

 

posted on 2020-08-27 10:17  一棵二叉树  阅读(9)  评论(0编辑  收藏  举报