Extracting images embedded in Excel Files

18 visualizzazioni (ultimi 30 giorni)
Jaco
Jaco il 27 Ago 2014
Modificato: DGM il 6 Feb 2023
Hi Everybody, I would like to know if there is a method for extracting images embedded in an Excel (*.xlsx) file?

Risposte (2)

Tushar Behera
Tushar Behera il 6 Feb 2023
Hi jaco,
I believe you want to know how to extract images from excel files.
You can use "ActiveX" function to acheive this. For example you can refer to this Matlab answer,
hope this resolves your query.
Regards,
Tushar
  1 Commento
Jaco Labuschagne
Jaco Labuschagne il 6 Feb 2023
Hi Tushar, Gasp. 9 years later... (You know how long I've been holding a pee waiting for that answer... 🤣😂🤣). Thanks for the answer. I just wish I could remember what I was trying to do with the question. I will dig through and see. :D

Accedi per commentare.


DGM
DGM il 6 Feb 2023
Modificato: DGM il 6 Feb 2023
If all you need is to extract images, you can do that directly. The attached xlsx file contains two embedded PNGs and a JPG. One of the PNG files has transparent content, though note that I'm discarding it.
For what it's worth, the troubles with automagically handling the variable presence of alpha content are the same regardless of whether the images were embedded in a document or came straight from the disk.
fname = 'Book1.xlsx';
% unzip the file
tempdir = 'docdump';
unzip(fname,tempdir)
% get the location of the embedded media
dirinfo = dir(fullfile(tempdir,'xl/media/*.*'));
nfiles = numel(dirinfo);
% try to read everything
allimages = {};
for k = 1:nfiles
thisfname = fullfile(dirinfo(k).folder,dirinfo(k).name);
try
[thispict map alpha] = imread(thisfname);
catch
fprintf('%s is not a readable image file\n',thisfname)
continue;
end
if ~isempty(map)
% if the image is indexed color, convert to RGB
thispict = ind2rgb(thispict,map);
end
if ~isempty(alpha)
% if the image has alpha content, you'll have to figure out how you want to handle it
% you could attach it (IA/RGBA output)
% note that this won't directly work with montage/imshow/imwrite
% as nothing in MATLAB/IPT knows what to do with attached alpha
% could be worked around by conditionally splitting alpha as needed
%thispict = joinalpha(thispict,alpha); % uses MIMT (FEX)
% ... or you could composite it with some matting (collapse to I/RGB output)
% this makes it so that imshow/montage will handle the image
% but you're losing the actual alpha content
%thispict = alphasafe(joinalpha(thispict,alpha)); % uses MIMT (FEX)
% or you could do something else to manage a cumbersome
% unattached alpha (I+A/RGB+A) workflow, as is canonical with base tools
% perhaps build a second cell array containing alpha pages?
% would then require conditional handling every time you call
% imshow/imwrite/etc
end
allimages = [allimages {thispict}]; %#ok<AGROW>
end
/users/mss.system.QUqTMs/docdump/xl/media/. is not a readable image file /users/mss.system.QUqTMs/docdump/xl/media/.. is not a readable image file
% remove the temp directory
rmdir(tempdir,'s')
% show the images that we found
% i'm setting the bgcolor so that it's clear what the extents are
montage(allimages,'backgroundcolor',[0.7 0.3 1])
Since this doesn't use actxserver, this approach doesn't require that you're using Windows.
See also:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by