Sep-13-2017, 04:57 AM
Is there anybody here who knows openpyxl well?
I wanted to make a little program to insert student photos next to their names. This is the first time I have used python. I managed to make it work and successfully insert the images in the correct cells.
I only opened 1 sheet of the file and made it the active sheet. At the end of the code is:
wb.save(pathToExcel + newname)
However, when I then save the file, the photos which are already in the other sheets are all gone! Not 1 photo left in any other sheet.
This is somewhat unexpected, as I did not touch those sheets.
Can anyone explain this or tell me how to prevent this?
Edit: I just opened an excel file, opened the first sheet, which is class 4, then saved it again. All the photos are now gone! Below is from the interactive shell.
I wanted to make a little program to insert student photos next to their names. This is the first time I have used python. I managed to make it work and successfully insert the images in the correct cells.
I only opened 1 sheet of the file and made it the active sheet. At the end of the code is:
wb.save(pathToExcel + newname)
However, when I then save the file, the photos which are already in the other sheets are all gone! Not 1 photo left in any other sheet.
This is somewhat unexpected, as I did not touch those sheets.
Can anyone explain this or tell me how to prevent this?
Edit: I just opened an excel file, opened the first sheet, which is class 4, then saved it again. All the photos are now gone! Below is from the interactive shell.
Quote:>>> sheets = wb.get_sheet_names()
>>> sheets
['课程表2017-2018冬季', '商务英语2016(4)', '商务英语2016(1)', '商务英语2016(3)', '商务英语2016(2)']
>>> ws = wb.get_sheet_by_name(sheets[1])
>>> ws
<Worksheet "商务英语2016(4)">
>>> wb.save(pathToExcel + nameOfFile)
>>>