Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
openpyxl saving files issue
#1
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.

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)
>>>
Reply
#2
This is from the openpyxl docs:
Quote:Warning
openpyxl does currently not read all possible items in an Excel file so images and charts will be lost from existing files if they are opened and saved with the same name.

The images will also be lost if they are saved in a file with another name! That is what I find!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  openpyxl issue - How to reset sheet.ins_row to the real last row ... ejwjohn 6 900 Nov-08-2023, 01:19 PM
Last Post: ejwjohn
  Trouble with saving openpyxl filename fjbianchi93 4 3,380 Apr-08-2022, 12:39 PM
Last Post: fjbianchi93
  Facing issue while saving workbook Abhisht 3 5,684 Aug-19-2020, 11:44 AM
Last Post: Larz60+
  extract zip from .msg files and saving according to date stamp of email natjo 3 3,005 Aug-13-2020, 09:35 PM
Last Post: bowlofred
  Saving Files Kristenl2784 3 2,058 Jul-13-2020, 04:36 PM
Last Post: bowlofred
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 3,446 May-04-2020, 08:02 PM
Last Post: deac33
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 1,970 Apr-29-2020, 12:03 AM
Last Post: bowlofred
  Downloading And Saving Zip Files To A Particular Path Folder eddywinch82 2 2,619 Jan-06-2020, 07:56 PM
Last Post: eddywinch82
  Openpyxl - while saving excel file getting error shubhamjainj 1 4,643 Apr-09-2019, 12:05 PM
Last Post: Larz60+
  Python 2.7.13 Issue Reading .txt files Properly username1145 3 2,585 Mar-24-2019, 03:08 PM
Last Post: username1145

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020