Extracting images from Excel spreadsheets
Posted: , Updated: Category: Computers Category: MS OfficeYou have images stuck inside a Microsoft Excel spreadsheet.
You need to save them to your hard drive.
Your problem is:
- There are multiple images. They’re on different worksheets.
- The pictures need to be named after the worksheet they were on.
- There might be multiple images on each worksheet.
Use this Python code. It interfaces with Microsoft Excel (so you’ll need to have Excel installed - I have Excel 2010.) You will also need the Python packages pywin32 and PIL.
- It will save all the images in the Excel workbook to the same folder as the workbook.
- The images will be saved as JPEG files.
- The images will be named after the worksheet they were on:
Sheet1.jpg,Sheet2.jpg, and so on. - If there was more than one image on a worksheet, the images will be numbered:
Sheet1.jpg,Sheet1_001.jpg,Sheet1_002.jpg, and so on.
Limitations: When Excel copies an image to the clipboard, it appears to use a fixed DPI. So the resolution of the image may be decreased.
Alternate approaches if this doesn’t suit you:
Save the Excel file to HTML format; all the images drop out as files with names like
image001.png.Dive into the Excel file; Excel 2007
xlsxfiles are justzipfiles inside. The images are stored in their original format (JPG or PNG) and original size. The images are helpfully namedimage112.jpgand so on.
| |