View a document using Word


[status,message] = docview(filename)
[status,message] = docview(filename,option)
[status,message] = docview(filename,option1...optionN)



[status,message] = docview(filename) opens the specified file as a Word document. Returns success or failure and, if appropriate, an error message. This command can then use Word to perform operations such as printing the document, updating table of contents and page numbers, and converting the document to PDF.


On Linux and Macintosh platforms, the report output displays in Apache OpenOffice™, which must be installed in /Applications/


[status,message] = docview(filename,option) operates on the file using the specified criterion.


[status,message] = docview(filename,option1...optionN) uses one or more additional criteria.


collapse all

Open a document in RTF format in Word. This example assumes the document magic-squares.rtf is on the MATLAB® path.


Print a document. This example assumes the document mydoc.doc is on the MATLAB path.


Use docview to update TOC fields in a document, convert the document to PDF, and close a Word document. This command creates the document mytocdoc.pdf in the current folder. This example assumes the document mytocdoc.docx is on the MATLAB path.


Input Arguments

collapse all

Name of file to view, print, or update, specified as the full path name.

Additional criteria for viewing the file, specified as one of these values:

  • 'updatefields' — Update fields, such as the TOC.

  • 'updatedocxfields' — Update fields in a DOCX document.

  • 'convertdocxtopdf' — Convert a DOCX document to PDF. Use this option only with Microsoft® Office on a Windows® system.

  • 'showdocxaspdf' — Convert a DOCX document to PDF and open in a PDF viewer. Use this option only with Microsoft Office on a Windows system.

  • 'unlinkdocxsubdoc' — Replace links to other documents with the content of those documents. Use this option only with Microsoft Office on a Windows system. To learn about subdocuments, see mlreportgen.dom.DOCXSubDoc.

  • 'printdoc' — Print the document.

  • 'closeapp' — Close Word after completing all other actions. Enter this option after the other options.

Data Types: char

Output Arguments

collapse all

Success status of the specified actions, returned as 0 when the action was not completed and 1 for success.

Error or warning information, returned as a character vector.

Introduced before R2006a