Main Content

Work withMicrosoft纪录片nts Using .NET

This example uses classes from theMicrosoft.Office.Interop.Word.ApplicationClassclass. For information about the class and using the interface with different versions ofMicrosoft®, refer to documentation on the MSDN®websitehttps://docs.microsoft.com/en-us/.

The following code creates a Word document:

NET.addAssembly('microsoft.office.interop.word'); wordApp = Microsoft.Office.Interop.Word.ApplicationClass; wordDoc = wordApp.Documents; newDoc = Add(wordDoc);

If you want to type directly into the document, type the MATLAB®command:

wordApp.Visible = true;

Put the cursor into the document window and enter text.

To name the documentmyDocument.docxand save it in theMy Documentsfolder, type:

SaveAs(newDoc,'myDocument.docx');

When you are finished, to close the document and application, type:

Save(newDoc); Close(newDoc); Quit(wordApp);

Related Topics

External Websites