below my code:
import openpyxl
# file 1:
path = "C:\\Users\\Admin\\Desktop\\TEST.xlsx"
wb_1 = openpyxl.load_workbook(path, read_only=True)
ws_1 = wb_1[wb_1.sheetnames[0]]
# file 2 (it's a new file):
wb_2 = openpyxl.Workbook()
ws_2 = wb_2.active
ws_2.title = "SHEET"
# copy the rows placed in file 1 into the file 2:
def GetList(row):
list_for_row_values = []
for cell in row:
list_for_row_values.append(cell.value)
return list_for_row_values
for row in ws_1.rows:
list_for_row_values = GetList(row)
ws_2.append(list_for_row_values)
wb_2.save("C:\\Users\\Admin\\Desktop\\result.xlsx")
in this example the script copies the rows placed in the first sheet of the TEST.xlsx file into a new one named "result.xlsx". the script works, but it copies only the content of the cells, and not theirs styles. it means that in the new files the wrap text, the original font, etc.. will be not enabled. how can I copy the style too? I tried many instructions but they didn't work. I'm not an expert with openpyxl. can you help me to modify this simple code in order to reach my goal?