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

13 Ansichten (letzte 30 Tage)
I want to export an image file to a Word file without using the PUBLISH function or manually copying and pasting the figure.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 17 Jun. 2021
Bearbeitet: MathWorks Support Team am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by