Dec-29-2020, 05:39 PM
Thank You! I will check this out.
(Dec-29-2020, 09:28 AM)Pedroski55 Wrote: Not too sure exactly what you want.
I don't have to copy any formulas or charts, so I never tried and I don't know about that.
I have to update my attendance + scores timetable each week.
This is the first step, may be that will help. It copies all cells in each sheet, after column 9, to a target file.
def copyOldData(): print(f'Opening the file attendanceSummer2020_{clas}latestPyMade.xlsx ....') pathToExcel = f'/home/pedro/attendanceSummer2020/{clas}/' attendanceFile = f'attendanceSummer2020_{clas}latestPyMade.xlsx' target = f'attendanceSummer2020_First9colsOnly{clas}.xlsx' saveFileName = attendanceFile.split('.') outputFile = saveFileName[0] + '_Step1.xlsx' sourceFile = openpyxl.load_workbook(pathToExcel + attendanceFile) sourceSheetNames = sourceFile.sheetnames targetFile = openpyxl.load_workbook(pathToExcel + target) targetSheetNames = targetFile.sheetnames # this inserts the maximum attendance value in the target file for sheet in sourceSheetNames: sourceFileActiveSheet = sourceFile[sheet] targetFileActiveSheet = targetFile[sheet] targetFileActiveSheet.cell(row=1, column=5, value='max Attendance') maxAttendance = sourceFileActiveSheet.cell(row=2, column=5).value # get the value targetFileActiveSheet.cell(row=2, column=5, value=maxAttendance) # write the value # copy all data after column 9 to the target file # move everything up 3 columns for sheet in sourceSheetNames: sourceFileActiveSheet = sourceFile[sheet] targetFileActiveSheet = targetFile[sheet] maxRowSourceFile = sourceFileActiveSheet.max_row maxColSourceFile = sourceFileActiveSheet.max_column for rowNum in range(1, maxRowSourceFile + 1): for colNum in range(10, maxColSourceFile + 1): # copy everything after column 9 value = sourceFileActiveSheet.cell(row=rowNum, column=colNum).value targetFileActiveSheet.cell(row=rowNum, column=colNum + 3, value=value) # move everything right 3 columns print('Saving file as ' + outputFile) targetFile.save(pathToExcel + outputFile) print('Step 1 done, old data copied')