mlreportgen.utils.WordDoc class

Package: mlreportgen.utils
Superclasses:

Wrap a Microsoft Word doc file

Description

This utility wraps a Word document file (.docx or .rtf) into an object. You can then manipulate the object using the methods of this utility.

Construction

docobj = mlreportgen.utils.WordDoc(filename) wraps a Word document file and returns it as a Word doc object. Only one WordDoc object can exist for each Word document file.

Input Arguments

expand all

Path to a Word document file, specified as a string or character vector.

Output Arguments

expand all

WordDoc object, returned as a wrapped document object file.

Properties

expand all

Path to a Word document file, specified as a string or character vector.

Methods

show

Make Word document visible

mlreportgen.utils.WordDoc.show(wordDoc)

hide

Hide Word document

mlreportgen.utils.WordDoc.hide(wordDoc)

close

Close Word document

mlreportgen.utils.WordDoc.close(wordDoc) or mlreportgen.utils.WordDoc.close(wordDoc,true) closes the Word document only if there are no unsaved changes.

mlreportgen.utils.WordDoc.close(wordDoc,false) closes the Word document even if there are unsaved changes.

save

Save Word document

mlreportgen.utils.WordDoc.save(wordDoc)

update

Update Word document fields

mlreportgen.utils.WordDoc.update(wordDoc)

mlreportgen.utils.WordDoc.update(wordDoc,0) forces update even if there are unsaved document fields

print

Print Word document

mlreportgen.utils.WordDoc.print(wordDoc)

saveAsDoc

Save as doc file with same file name

mlreportgen.utils.WordDoc.saveAsDoc(wordDoc)

Save as doc file with specified file name

docFullPath = mlreportgen.utils.WordDoc.saveAsDoc(wordDoc,docFileName)

exportToPDF

Export to PDF document with same file name

mlreportgen.utils.WordDoc.exportToPDF(wordDoc)

Export to PDF document with specified file name

pdfFullPath = mlreportgen.utils.WordDoc.exportToPDF(wordDoc,pdfFileName)

unlinkFields

Remove links from fields in the Word document

mlreportgen.utils.WordDoc.unlinkFields(wordDoc)removes links from all fields

mlreportgen.utils.WordDoc.unlinkFields(wordDoc,fieldType1) removes links from all instances of fieldType1 fields. For example, mlreportgen.utils.WordDoc.unlinkFields(wordDoc,’wdHyperLink’) removes all hyperlink fields.

mlreportgen.utils.WordDoc.unlinkFields(wordDoc,fieldType1,fieldType2) removes links from all instances of both fieldType1 and fieldType2 fields.

See Word FieldType Enumeration for information on Word fields.

unlinkSubdocuments

Remove links to subdocuments and copy subdocuments into master document

mlreportgen.utils.WordDoc.unlinkSubdocuments(wordDoc)

isOpen

Test if Word document is open

mlreportgen.utils.WordDoc.isOpen(wordDoc)

isReadOnly

Test if Word document is read-only

mlreportgen.utils.WordDoc.isReadOnly(wordDoc)

isSaved

Test if Word document is saved

mlreportgen.utils.WordDoc.isSaved(wordDoc)

isVisible

Test if Word document is visible

mlreportgen.utils.WordDoc.isVisible(wordDoc)

netobj

Return a .NET Word document object, which allows using the .NET interface on this object

mlreportgen.utils.WordDoc.netobj(wordDoc)

Examples

Create WordDoc Object and .NET Object

This example creates a WordDoc object from the existing MyWordDoc.docx file.

docobj = mlreportgen.utils.WordDoc("MyWordDoc.docx");
netobj(docobj);

Introduced in R2018b