How can I paste plots from Matlab to Word ver 15 (Office 2013)?

조회 수: 5 (최근 30일)
Hans Christiansson
Hans Christiansson 2014년 3월 31일
The save2word.m from your Matlab Central worked fine until I used the new Word version in Office 2013.
This code (found on Matlab Central) works fine but not if I have an already existing Word document and wants to add figures in append mode it doesn’t work even if I use this in the beginning: op = invoke(word.Documents,'Open',filespec); it will always over write the first figure in the Word file.
% Create a Word Automation Server and make it visible on the screen. % This would be the equivalent of opening MS Word word = actxserver('word.application'); set(word,'visible',1);
% Create a new document doc1 = invoke(word.documents,'add');
% Specify the location by creating a range range = invoke(doc1,'range'); x = 0:0.1:2*pi; y = sin(x);
numOfFigures = 10;
% Loop through and create the figures for n = 1:numOfFigures % Adds a new paragraph invoke(doc1.Paragraphs,'Add');
% Select the new paragraph range
range = invoke(doc1,'range',doc1.Paragraphs.Item(n).Range.Start);
% Create a MATLAB Figure and copy it to the clipboard.
if mod(n,2) == 0
plot(1:10)
else
plot(x,y,'r-*');
end
print(gcf,'-dmeta');
% Paste the figure into the Word Document range that was previously selected
invoke(range,'Paste')
end
% Delete the handles that were created
delete(word)

답변 (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