I have an Excel source file in a source folder (*.xlsm
) and another file (also *.xlsm
) that contain some data. I have to create a third file, that has to be a *.xls
file, that is basically the Excel source file that contains some data of the second file. In order to do that I have written this code:
from openpyxl import load_workbook
file1 = "C:\\Users\Desktop\file1.xlsm"
file2 = "C:\\Users\Desktop\file2.xlsm"
file3 = "C:\\Users\Desktop\file3.xls"
wb1 = load_workbook(file1)
sheet1 = wb1["Sheet1"]
wb2 = load_workbook(file2)
sheet2 = wb2["Sheet1"]
sheet1["A1"].value = sheet2["A1"].value
wb1.save(file3)
The code seems to be OK and doesn't return any error, but the I cannot open the created file3
.
I don't understand why, I tried to change the extension of the third file but both *.xlsx
and *.xlsm
show this problem. I also tried to delete the line part
sheet1["A1"].value = sheet2["A1"].value
To understand if the problem was linked to the writing of the sheet, but the problem remains.