- The following code snippet explains how to specify a word template using MATLAB.
- You can modify this code accordingly.
Saving a word document in MatLab 2021b
조회 수: 29 (최근 30일)
이전 댓글 표시
I have written a script that opens a figure file, which has multiple figures in it and returns a figure array. It then creates a artxserver for the Word application and creates a new word document. It then copies and pastes the figures sequentially to the Word document. The script works to this point and I have a Word document with the figures sequentially pasted into it. I would like the script to then save the Word document and then close the Word document. For closing, I use word.Quit(). The variable word is created earlier by word=actxserver('Word.Application'). The problem is to save the Word document before closing Word. I have looked in the MathWorkssupport section and have found this syntax: "document.SaveAs([path filename])". The variable document is created by document=word.Document.Add, which creates the blank Word document in the script. I get the error "unrecognized function or variable 'SaveAs' ". I cannot find the proper syntax to save the newly created Word document in MatLab. I am using Word 2016. Any suggestions are appreciated. Thank you.
댓글 수: 0
답변 (1개)
Vishesh
2022년 10월 27일
% Create a Word Automation Server and make it visible on the screen.
% This would be the equivalent of opening MS Word
word = actxserver('word.application');
word.visible =1;
%Pass the fully qualified name of document template that you want to use
doc1 = word.documents.Add('C:\Users\~\AppData\Roaming\Microsoft\QuickStyles\MyStyle1.dotx');
%Save the document. If the full qualified file name is not given then the
%file is saved to My Documents on Windows OSs
word.ActiveDocument.SaveAs2('Test.docx');
% Delete the handles that were created
word.Quit
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!