필터 지우기
필터 지우기

embedding matlab figures (.fig files) automatically into a Word document

조회 수: 54 (최근 30일)
Jorge Rivé
Jorge Rivé 2013년 10월 10일
댓글: Mukund 2020년 7월 30일
Hi,
I know how to use the Publish and notebook functionality to copy figures into Word documents. However, is there a way to copy the fig file as an embedded object into Word, so that anyone reading the doc on a computer (equipped with Matlab) can double click on the icon in the Word doc and launch Matlab to open the figure? This is useful when the data in the plot is not readily visible due to the axis and /or scale, and you want to be able to zoom in and out to review the plot. Any way to do this?
Thanks, Jorge
  댓글 수: 1
Cedric
Cedric 2013년 10월 28일
편집: Cedric 2013년 10월 28일
It's not a solution but a hint.. maybe. If you have time for that, you could try using ActiveXServer or .NET. Here is an example for building a table with .NET (that I saved once from a thread on StackOverflow):
%# Register Word assembly
NET.addAssembly('microsoft.office.interop.word');
%# Create an instance of Word
wordApp = Microsoft.Office.Interop.Word.ApplicationClass;
%# Get the object that handles documents
wordDoc = wordApp.Documents;
%# Add a new document
newDoc = wordDoc.Add;
%# Make Word visible
wordApp.Visible = true;
%# Get the selection object to manage selected area
selection = wordApp.Selection;
%# Create a table
table = newDoc.Tables.Add(selection.Range, 3, 5);
%# Add grid lines
table.Style = 'Table Grid';
About ActiveXServer, just Google
actxserver('Word.Application')
and you'll find quite a few threads or documents (e.g. this).
I didn't investigate further because I had no use for it, but if I had to insert an image in a Word document, this is probably where I would start.

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

답변 (2개)

Cedric
Cedric 2013년 10월 31일
편집: Cedric 2013년 10월 31일
Mixing information from..
I could build the following example..
% - Build some plot.
x = 0 : 1e-2 : 2*pi ;
y = sin( x ) ;
plot( x, y ) ;
grid on ;
xlabel( 'Angle \in [0,2\pi[' ) ;
ylabel( 'Sine' ) ;
% - Save as JPEG image (use absolute path!).
jpegLocator = fullfile( cd, 'sine.jpeg' ) ;
saveas( gcf, jpegLocator, 'jpeg' ) ;
% - Build MS Word document, insert image, save (use absolute path!).
docxLocator = fullfile( cd, 'sine.docx' ) ;
word = actxserver( 'word.application' ) ;
word.Visible = true ; % Set to false in final version.
document = word.Documents.Add() ;
document.InlineShapes.AddPicture( jpegLocator, false, true ) ;
document.SaveAs2( docxLocator ) ;
word.Quit() ;
Hope it helps!
  댓글 수: 3
Cedric
Cedric 2013년 11월 11일
Hi Jorge,
I would guess that it's no doable, if only because I have never seen anything close to this. Yet, if you find a solution, please update this thread with a short description, because I too would have a strong interest for that!
Regards, Cedric
Mukund
Mukund 2020년 7월 30일
Could you please add the Answer you obtained.
Probably, it will be useful for Matlab community.

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


Yatin
Yatin 2013년 10월 15일
편집: Yatin 2013년 10월 15일
Hi,
Once you have a image in your word document you can associate it with a hyperlink to a .m file or a .fig file in MATLAB, so that when you click on the image in the word file, it will open the MATLAB with the .fig file or the .m file for editing. Note however, that instead of double-clicking the image you will have to use Cntrl+Click to start up MATLAB. Also this procedure assumes that you have MATLAB installed on your Windows Machine and that the .m and .fig extensions are associated with MATLAB in the OS(Windows typically).
  댓글 수: 1
Jorge Rivé
Jorge Rivé 2013년 10월 24일
Thanks for the response. However, I don't think it achieves what I'm looking for. I would still have to manually go and do the associations one by one. Is that right?
What I'm looking for is a way to automate the addition of embedded figure files or even the hyperlinks in a Word doc with either Publish or some other way.

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

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by