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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by