Question: I want to write a nested dictionary to a sheet using openpyxl in which the keys should be used as header and values which are also a inner dictionary which has list values in it as well to be the records for header in which parent keys they are present. My code hasn't been able to achieve the complete the scenario but I was able divide data into required stages which I want but the issues are blank cells and List values which I want to be divided like: LKP_GetData -> ('FIL_UpdateChangedRecord', 'EXP_DetectChanges') in stage3 which has list values should be broken to LKP_GetData -> ('FIL_UpdateChangedRecord') and LKP_GetData -> ('EXP_DetectChanges') in stage 3 and placed in individual cells. Same goes with other such data in other stages  My code: import openpyxl # Your nested dictionary nested_dict = { 0: {'DIM_NRC_CUSTOMER_TMP': ['SQ_DIM_NRC_CUSTOMER_TMP'], 'SAT_CONTACT': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER_DERIVED': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER_PREDICTED': ['SQ_HUB_CUSTOMER'], 'HUB_CUSTOMER': ['SQ_HUB_CUSTOMER']}, 1: {'SQ_DIM_NRC_CUSTOMER_TMP': ['UPDTRANS'], 'SQ_HUB_CUSTOMER': ['LKP_SH_MOBILE_PH_NO', 'EXP_PREPARE_DATA', 'lkp_LNK_CUSTOMER_CUST_GROUP', 'LKP_CIS_CUSTOMER', 'lkp_REF_EARLY_ADOPTERS', 'LKP_GPRS_USAGE_AVG', 'LKP_EMP_FLAG', 'lkp_SH_MOBILE_PH_Active', 'exp_MOBILE_PH_NO']}, 2: {'UPDTRANS': ['DIM_NRC_CUSTOMER_Update'], 'LKP_SH_MOBILE_PH_NO': ['EXP_PREPARE_DATA'], 'EXP_PREPARE_DATA': ['FIL_InsertNewRecord', 'FIL_UpdateChangedRecord', 'EXP_DetectChanges', 'LKP_GetData'], 'lkp_LNK_CUSTOMER_CUST_GROUP': ['EXP_PREPARE_DATA'], 'LKP_CIS_CUSTOMER': ['EXP_PREPARE_DATA'], 'lkp_REF_EARLY_ADOPTERS': ['EXP_PREPARE_DATA'], 'LKP_GPRS_USAGE_AVG': ['EXP_PREPARE_DATA'], 'LKP_EMP_FLAG': ['EXP_PREPARE_DATA'], 'lkp_SH_MOBILE_PH_Active': ['EXP_PREPARE_DATA'], 'exp_MOBILE_PH_NO': ['lkp_SH_MOBILE_PH_Active']}, 3: {'FIL_InsertNewRecord': ['UPD_ForceInserts'], 'FIL_UpdateChangedRecord': ['UPD_ChangedUpdate'], 'EXP_DetectChanges': ['FIL_InsertNewRecord', 'FIL_UpdateChangedRecord'], 'LKP_GetData': ['FIL_UpdateChangedRecord', 'EXP_DetectChanges']}, 4: {'UPD_ForceInserts': ['DIM_NRC_CUSTOMER_Insert'], 'UPD_ChangedUpdate': ['DIM_NRC_CUSTOMER_TMP_Insert']} } # Create a new Excel workbook workbook = openpyxl.load_workbook("C:\\Desktop\\multiple_sheets_details_new.xlsx") sheet = workbook.create_sheet(title = "MAPPING",index=0) # Write headers headers = [f'Stage{i}' for i in nested_dict.keys()] sheet.append(headers) # Write data to Excel for key in set(key for inner_dict in nested_dict.values() for key in inner_dict): row_data = [] for inner_dict in nested_dict.values(): if key in inner_dict and isinstance(inner_dict[key], list): row_data.append(f'{key} -> {tuple(inner_dict[key])}') else: row_data.append(inner_dict.get(key, [""])[0]) sheet.append(row_data) # Save the workbook workbook.save("C:\\Desktop\\multiple_sheets_details_new.xlsx")  The issue is I am getting an output where there are blank cells in each column record(stage 0, stage 1, etc.) and I want them to be in sequence in each column without any blank cells. Also the List values should be broken in to key value records in the same column. Like LKP_GetData -> ('FIL_UpdateChangedRecord', 'EXP_DetectChanges') in stage3 which has list values should be broken to LKP_GetData -> ('FIL_UpdateChangedRecord') and LKP_GetData -> ('EXP_DetectChanges') in stage 3 and placed in individual cells My Output:  I am expecting the output to look like: 

Answer: Thanks for the expected result screen shot, I was close.  Either way the easiest is probably just reading the dict and adding the values to the cells as they are read. Here is a quick option which I think is correct though may not be sorted the same way as your example; import openpyxl from openpyxl.utils.cell import get_column_letter from openpyxl.styles import Font # Your nested dictionary nested_dict = { 0: {'DIM_NRC_CUSTOMER_TMP': ['SQ_DIM_NRC_CUSTOMER_TMP'], 'SAT_CONTACT': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER_DERIVED': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER': ['SQ_HUB_CUSTOMER'], 'SAT_CUSTOMER_PREDICTED': ['SQ_HUB_CUSTOMER'], 'HUB_CUSTOMER': ['SQ_HUB_CUSTOMER']}, 1: {'SQ_DIM_NRC_CUSTOMER_TMP': ['UPDTRANS'], 'SQ_HUB_CUSTOMER': ['LKP_SH_MOBILE_PH_NO', 'EXP_PREPARE_DATA', 'lkp_LNK_CUSTOMER_CUST_GROUP', 'LKP_CIS_CUSTOMER', 'lkp_REF_EARLY_ADOPTERS', 'LKP_GPRS_USAGE_AVG', 'LKP_EMP_FLAG', 'lkp_SH_MOBILE_PH_Active', 'exp_MOBILE_PH_NO']}, 2: {'UPDTRANS': ['DIM_NRC_CUSTOMER_Update'], 'LKP_SH_MOBILE_PH_NO': ['EXP_PREPARE_DATA'], 'EXP_PREPARE_DATA': ['FIL_InsertNewRecord', 'FIL_UpdateChangedRecord', 'EXP_DetectChanges', 'LKP_GetData'], 'lkp_LNK_CUSTOMER_CUST_GROUP': ['EXP_PREPARE_DATA'], 'LKP_CIS_CUSTOMER': ['EXP_PREPARE_DATA'], 'lkp_REF_EARLY_ADOPTERS': ['EXP_PREPARE_DATA'], 'LKP_GPRS_USAGE_AVG': ['EXP_PREPARE_DATA'], 'LKP_EMP_FLAG': ['EXP_PREPARE_DATA'], 'lkp_SH_MOBILE_PH_Active': ['EXP_PREPARE_DATA'], 'exp_MOBILE_PH_NO': ['lkp_SH_MOBILE_PH_Active']}, 3: {'FIL_InsertNewRecord': ['UPD_ForceInserts'], 'FIL_UpdateChangedRecord': ['UPD_ChangedUpdate'], 'EXP_DetectChanges': ['FIL_InsertNewRecord', 'FIL_UpdateChangedRecord'], 'LKP_GetData': ['FIL_UpdateChangedRecord', 'EXP_DetectChanges']}, 4: {'UPD_ForceInserts': ['DIM_NRC_CUSTOMER_Insert'], 'UPD_ChangedUpdate': ['DIM_NRC_CUSTOMER_TMP_Insert']} } # Create a new Excel workbook workbook = openpyxl.load_workbook("C:\\Desktop\\multiple_sheets_details_new.xlsx") sheet = workbook.create_sheet(title="MAPPING", index=0) # Write headers headers = [f'Stage{i}' for i in nested_dict.keys()] sheet.append(headers) for col, inner_dict in enumerate(nested_dict.values(), 1): row = 2 # Start from row 2 sheet.cell(row=row-1, column=col).font = Font(bold=True) # Bold the header cells sheet.column_dimensions[get_column_letter(col)].width = 60 # Set a larger column width for key in inner_dict: for item in inner_dict[key]: sheet.cell(row=row, column=col).value = f"{key} -> {str(item)}" row += 1 # Save the workbook workbook.save("C:\\Desktop\\multiple_sheets_details_new.xlsx")