Created
May 31, 2020 18:50
-
-
Save bhaskar253/9e7934dae53a723d8e03dc488c516634 to your computer and use it in GitHub Desktop.
Updating the existing cell of the excel file using Python (# Delete it once its use is over)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import openpyxl | |
| excel_file = openpyxl.load_workbook('records.xlsx') | |
| #print(excel_file.sheetnames) | |
| tc_sheet = excel_file['Testcases'] | |
| #currently_active_sheet = excel_file.active | |
| cell_obj = tc_sheet.cell(row=1, column=1) | |
| #print(f'{cell_obj.value}') | |
| #print(f'{tc_sheet["A1"].value}') | |
| #print(f'rows = {tc_sheet.max_row} & cols = {tc_sheet.max_column}') | |
| trows = int(tc_sheet.max_row) | |
| tcols = int(tc_sheet.max_column) | |
| lst = [{"id": "t_02.tc", "res": "FAIL"}, {"id": "t_01.tc", "res": "BLOCK"}] | |
| lst.sort(key=lambda i: int(i['id'].split('.tc')[0].split('t_')[1])) | |
| for d in lst: | |
| k = d['id'].split('.tc')[0] | |
| r = d['res'] | |
| for i in range(2, trows + 1): | |
| if tc_sheet.cell(row=i, column=1).value == k: | |
| tc_sheet.cell(row=i, column=3).value = r | |
| #for i in range(2, trows + 1): | |
| # tc_sheet.cell(row=i, column=3).value = 'PASS' | |
| excel_file.save('records.xlsx') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment