How can I automatically export an image to a Microsoft Word file without using the PUBLISH function in MATLAB 7.10 (R2010a)?
13 views (last 30 days)
Show older comments
MathWorks Support Team
on 3 Jun 2010
Edited: MathWorks Support Team
on 30 Jun 2021
I want to export an image file to a Word file without using the PUBLISH function or manually copying and pasting the figure.
Accepted Answer
MathWorks Support Team
on 17 Jun 2021
Edited: MathWorks Support Team
on 30 Jun 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!