Embed external files in published files
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
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
0 个评论
采纳的回答
  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
 2018-5-2
				Can you show me how to add a word document to an excel sheet as an object?
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


