#! python3 # blankRowInserter.py import openpyxl,os os.chdir(‘C:\\Users\\Administrator\\Python35-32‘) n=int(input(‘rowNum‘)) m=int(input(‘insertrowNum‘)) name=(‘updatedProduceSales2.xlsx‘) wb = openpyxl.load_workbook(name) wbnew=openpyxl.Workbook() sheet = wb.get_active_sheet() sheetnew=wbnew.get_active_sheet() for rowNum in range(1, sheet.max_row+1): if rowNum > n-1: for colNum in range(1,sheet.max_column+1): produceName = sheet.cell(row=rowNum, column=colNum).value sheetnew.cell(row=rowNum+m, column=colNum).value = produceName else: for colNum in range(1,sheet.max_column+1): produceName = sheet.cell(row=rowNum, column=colNum).value sheetnew.cell(row=rowNum, column=colNum).value = produceName wbnew.save(‘blankRowInserter.xlsx‘)
时间: 2024-10-05 20:21:28