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')