1

I have tried to extract pictures from excel, but after grouping the text or lines inserted in Excel with pictures, the pictures after the group cannot be completely extracted when extracting the pictures. What should I do?

This is the code I try

import os
import zipfile
import numpy as np
import win32com.client as win32
from PIL import Image

path = 'C:/Users/Peter/Desktop/test/'
count = 1
for file in os.listdir(path):
    new_file = file.replace(".xlsx",".zip")
    os.rename(os.path.join(path,file),os.path.join(path,new_file))
    count+=1

number = 0
list_dir = os.listdir(path)

for i in range(len(list_dir)):
    if 'zip' not in list_dir[i]:
        list_dir[i] = ''
while '' in list_dir:
    list_dir.remove('')

for zip_name in list_dir:
    azip = zipfile.ZipFile(path + zip_name)
    namelist = (azip.namelist())

    for idx in range(0,len(namelist)):
        #print(namelist[idx][:9])
        if namelist[idx][:9] == 'xl/media/':
        img_name = path + str(number)+'.jpg'
        f = azip.open(namelist[idx])
        img = Image.open(f)
        img = img.convert("RGB")
        img.save(img_name,"JPEG")
        number+=1 
        f.close()
azip.close()

for file in os.listdir(path):
    new_file = file.replace(".zip",".xlsx")
    os.rename(os.path.join(path,file),os.path.join(path,new_file))
    count+=1

This is my excel file, and the pictures are get from goole for trying, and I added text and arrows to go in. enter image description here

And this is the pictures I get, there is no text or line in the pictures. enter image description here

Peter
  • 100
  • 10

1 Answers1

1

I know very little about Excel, so there may be a much better explanation, but it seems to me that the annotations are stored in an OpenXML file called drawing1.xml inside your XLSX archive.

I can see your two red triangles and the label 40 as annotated below - note that val="ff0000" would correspond to red.

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks, then I know the next step to constrat the xml to image, I have found the web related,and I'll try it. [Python: converting an xml file to an image](https://stackoverflow.com/questions/58645562/python-converting-an-xml-file-to-an-image) – Peter Nov 05 '21 at 02:19