Embed external files in published files

조회 수: 2 (최근 30일)
Dominik
Dominik 2012년 5월 3일
Hi,
I use publish to Word-Document to document my analyses.
As part of the code I generate and external file (Excel sheet) which I would like to embed in the Published Word-Document created.
I understand it is possible to embed external graphics, but is there also a way of doing so with other external files?
Kind Regards, Dominik

채택된 답변

Eric
Eric 2012년 5월 3일
I don't know a lot about Matlab's built-in publishing capabilities, but I'd be surprised if what you are looking for is possible via that route.
Assuming you're running on Windows, what I would propose would be to create the Word document using your existing process and then embed the file using Word's COM interface. Let Word_fname be the name of the Word file in which you wish to embed a second file, called filename. These should be fully-resolved filenames. You can do something like:
%%Create COM objects
Word_COM = actxserver('Word.Application');
File_COM = Word_COM.Documents.Open(Word_fname);
Word_COM.Visible = 1;
%%Go to the end of the file
wdStory = 6;
Word_COM.Selection.EndKey(wdStory);
%%Try to get icon information
[pathstr, name, ext] = fileparts(filename);
applink = winqueryreg('HKEY_CLASSES_ROOT',ext);
try
app = winqueryreg('HKEY_CLASSES_ROOT',[applink '\DefaultIcon']);
if strcmpi(ext,'.xml')
icon_filename = 'C:\WINDOWS\system32\msxml3.dll';
icon_index = 0;
elseif strfind(app,',')
[token, remain] = strtok(app,',');
icon_filename = token;
icon_index = str2double(remain(2:end));%Strip off the comma and extract the icon index
else
icon_filename = 'C:\WINDOWS\system32\shell32.dll';
icon_index = 0;
end
catch ME
icon_filename = 'C:\WINDOWS\system32\shell32.dll';
icon_index = 0;
end
%%Embed object
Word_COM.Selection.TypeParagraph;%Add a carriage return
Word_COM.Selection.InlineShapes.AddOLEObject('',filename,false,true,icon_filename,icon_index,[name ext]);
Word_COM.Selection.TypeParagraph;%Add a carriage return
This isn't ideal since you need to post-process the Word document after publishing it, but you could turn this code into a function that is relatively simple to use.
Good luck,
Eric
  댓글 수: 1
Jethendra Phani Somarowthu
Jethendra Phani Somarowthu 2018년 5월 2일
Can you show me how to add a word document to an excel sheet as an object?

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

추가 답변 (0개)

카테고리

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