フィルターのクリア

Saving a word document in MatLab 2021b

51 ビュー (過去 30 日間)
George Pavlath
George Pavlath 2022 年 10 月 24 日
コメント済み: George Pavlath 2022 年 10 月 31 日
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.

回答 (1 件)

Vishesh
Vishesh 2022 年 10 月 27 日
  • The following code snippet explains how to specify a word template using MATLAB.
  • You can modify this code accordingly.
% 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
  1 件のコメント
George Pavlath
George Pavlath 2022 年 10 月 31 日
This works. The key is the "word.ActiveDocument.SaveAs2('Test.docx')" command. Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by