필터 지우기
필터 지우기

Extracting images embedded in Excel Files

조회 수: 13 (최근 30일)
Jaco
Jaco 2014년 8월 27일
편집: DGM 2023년 2월 6일
Hi Everybody, I would like to know if there is a method for extracting images embedded in an Excel (*.xlsx) file?

답변 (2개)

Tushar Behera
Tushar Behera 2023년 2월 6일
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
Jaco Labuschagne
Jaco Labuschagne 2023년 2월 6일
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

댓글을 달려면 로그인하십시오.


DGM
DGM 2023년 2월 6일
편집: DGM 2023년 2월 6일
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:

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by