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

show(wordDoc)

hide

Hide Word document

hide(wordDoc)

close

Close Word document

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

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

save

Save Word document

save(wordDoc)

update

Update Word document fields

update(wordDoc)

update(wordDoc,0) forces update even if there are unsaved document fields

print

Print Word document

print(wordDoc)

saveAsDoc

Save as doc file with same file name

saveAsDoc(wordDoc)

Save as doc file with specified file name

docFullPath = saveAsDoc(wordDoc,docFileName)

exportToPDF

Export to PDF document with same file name

exportToPDF(wordDoc)

Export to PDF document with specified file name

pdfFullPath = exportToPDF(wordDoc,pdfFileName)

unlinkFields

Remove links from fields in the Word document

unlinkFields(wordDoc)removes links from all fields

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

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

unlinkSubdocuments(wordDoc)

isOpen

Test if Word document is open

isOpen(wordDoc)

isReadOnly

Test if Word document is read-only

isReadOnly(wordDoc)

isSaved

Test if Word document is saved

isSaved(wordDoc)

isVisible

Test if Word document is visible

isVisible(wordDoc)

netobj

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

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