How can I automatically export an image to a Microsoft Word file without using the PUBLISH function in MATLAB 7.10 (R2010a)?
12 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2010-6-3
编辑: MathWorks Support Team
2021-6-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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!