from openpyxl import load_workbook
# Load the workbook and select the sheet
workbook2 = load_workbook('path_to_your_file.xlsx')
SDD_sheet = workbook2['SDD Input']
# Find the first empty cell in column C
row_idx = 6 # Assuming you want to start looking from row 6
while SDD_sheet.cell(row=row_idx, column=3).value is not None:
row_idx += 1
# Iterate over the DataFrame and write to the sheet from the first empty cell onwards
for r_offset, row in enumerate(SDD_Ready.itertuples(index=False, name=None)):
for c_idx, value in enumerate(row, start=1):
SDD_sheet.cell(row=row_idx + r_offset, column=c_idx, value=value)
# Save the workbook to the final path
workbook2.save(final_path)
Trying to paste a dataframe into an existing excel sheet, but for some reason, even after specifying, it just pastes in the same cell as always, which will be cell A6 in the excel sheet. Am i missing something? Thanks a lot.