How can I automatically export an image to a Microsoft Word file without using the PUBLISH function in MATLAB 7.10 (R2010a)?

조회 수: 13 (최근 30일)
I want to export an image file to a Word file without using the PUBLISH function or manually copying and pasting the figure.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 6월 17일
편집: MathWorks Support Team 2021년 6월 30일
You can work with the Word Object Model in MATLAB to add an image to a Word file. For example, suppose you have an image 'test_img.png'. The following script will look for this image in the current working directory and export the image to a word file, 'mydoc.doc' in the current working directory:
imgName =[pwd, '\test_img.png'];
fileName = [pwd, '\mydoc.doc'];
wordApplication=actxserver('Word.Application');
% Define constants.
wdFormatDocument = 0;
%set(wordApplication,'Visible',1); % Great for debugging.
documents = wordApplication.Documents;
% Create a new document.
documents.Add;
doc = documents.Item(documents.Count);
selection = wordApplication.Selection;
% add picture
selection.InlineShapes.AddPicture(imgName); % absolute path to the image
selection.TypeParagraph;
selection.TypeParagraph;
% save and close
doc.SaveAs(fileName,wdFormatDocument);
doc.Close(0);
wordApplication.Quit
For more information on Word Object Model, please refer the following webpage:
Note that the above script requires Microsoft Word installed on the system.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by