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.
And this is the pictures I get, there is no text or line in the pictures.