I have done a lot of research and failed to solve this problem, so I am coming here to ask for help. I read the worksheet object from a file below,
sheet_2_workbook = openpyxl. load_workbook(sheet_2_path)
sheet_2 = sheet_2_workbook.worksheets\[0\]
As described in the title, I want to add it to the new sheet of the existing .xlsx document, how should I do it?
I tried to realize this as below, but the new document obtained by this method will lose some of the original formatting, including the cell background color and merged cells
old_wb = openpyxl. load_workbook(file_list[i])
old_sheet_name = old_wb. get_sheet_names()[0]
old_ws = old_wb[old_sheet_name]
ws2 = combined_wb.create_sheet(sheet_name)
for row in old_ws.values:
ws2.append(row)
I am sure that the worksheet object read in the file contains these formats, because the .xlsx document I dumped with the following code has the format mentioned above
sheet_2_workbook. save(filename = temp_save_path)