Print Figure to Word Document with Current Figure Size

6 ビュー (過去 30 日間)
lynniz
lynniz 2012 年 2 月 28 日
コメント済み: Georgi Botev 2020 年 1 月 7 日
Hi All,
I am currently using a function on File Exchange to print my figure to a Word document. I noticed the size of the figure on the doc was a lot smaller than the actual size of the figure. I tried to set the "position" and "paperPosition" of the figure before printing, but neither setting affected the figure size. Could anyone please help me on this issue? I just want to make the figure in the doc the same size as the current figure size in MATLAB. The code that I used from File Exchange is below. Any help would be greatly appreciated.
Thank you,
Lynniz
print(gcf)
% Find end of document and make it the insertion point:
end_of_doc = get(actx_word_p.activedocument.content,'end');
set(actx_word_p.application.selection,'Start',end_of_doc);
set(actx_word_p.application.selection,'End',end_of_doc);
% Paste the contents of the Clipboard:
%also works Paste(ActXWord.Selection)
invoke(actx_word_p.Selection,'Paste');

採用された回答

Eric
Eric 2012 年 2 月 28 日
I print figures to Word in a different way. First print the figure to a temporary file using something like
temp_fname = [tempname '.png'];%Create a temporary name
print(['-f' sprintf('%d',figure_number)], '-dpng', temp_fname);
where figure_number is the number of the figure you're working with.
Then insert the picture using something like
Word_COM.Selection.InlineShapes.AddPicture(temp_fname);
where Word_COM is the COM object for Word.
Lastly, delete the temporary file and set the size of the picture using
delete(temp_fname);
set(Pic, 'ScaleHeight', scale, 'ScaleWidth', scale);
where scale is some user-defined value. You can adjust the scale until you get something you like.
Good luck,
Eric
  3 件のコメント
Subhamoy Saha
Subhamoy Saha 2019 年 3 月 20 日
編集済み: Subhamoy Saha 2019 年 3 月 20 日
HI lynniz, I'm also having similar trouble. Would you please explain what does 'Pic' refer to in the following line of the code given by Eric?
set(Pic, 'ScaleHeight', scale, 'ScaleWidth', scale);
Georgi Botev
Georgi Botev 2020 年 1 月 7 日
Pic is assigned when for example using an .AddPitcure metohd
Pic = selection.InlineShapes.AddPicture(ImPathName); % absolute path to the image
set(Pic, 'ScaleHeight', scale, 'ScaleWidth', scale);
Maybe this will help you reference the Pic variable

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by