[file,status,errMsg] = officedoc(fileName, 'open', propName,propValue,...) [data,status,errMsg] = officedoc(file, 'read', propName,propValue,...) [status,errMsg] = officedoc(file, 'write', propName,propValue,...) [status,errMsg] = officedoc(file, 'format', propName,propValue,...) [status,errMsg] = officedoc(file, 'close', propName,propValue,...) officedoc(file, 'display', visibleFlag) helpText = officedoc('help', helpType)
officedoc reads/writes/appends and formats data, images and screenshots in Microsoft Office documents. Supported formats include XLS (Excel), DOC (Word) and PPT (PowerPoint). Opening/closing COM server connection and files is user-controllable, enabling very fast sequential writes. Numerous format properties enable highly-customizable output.
[FILE, STATUS, ERRMSG] = officedoc(FILENAME, 'open', ...) opens the specified FILENAME for later reading/writing. The returned FILE struct may be used later to read/write/format file data. The optional STATUS output argument is 0 in case of sucess or -1 in case of error, when the error message is specified in another optional argument ERRMSG. The document format is determined from the FILENAME extension (xls, doc or ppt). Use the optional properties to set open mode etc.
[DATA, STATUS, ERRMSG] = officedoc(FILE, 'read', ...) reads DATA from specified FILE, a struct that was returned from officedoc(...,'open'). The basic DATA format is a structure based on the top-level division of the document (worksheets, chapters or slides, depending on file format). The structure fields are the division names and the field contents is the data within them. If only a single division was found or requested, then DATA contains the division's data immediately (not contained within a structure). STATUS is -1 in case of error, or the actual number of data elements/characters read in case of success.
officedoc(FILE, 'write', ...) writes data to the specified FILE. Use the optional properties to specify range and data. If no range is specified, then the last file position (before file was last closed) will be used (XLS/DOC only, not PPT). STATUS is -1 in case of error, or actual number of data elements/characters writen in case of success. Formating properties may be specified for the written data, saving a separate officedoc(FILE, 'format', ...) command.
officedoc(FILE, 'format', ...) formats data in the specified FILE. Use the optional properties to specify range and format options.
officedoc(FILE, 'close', ...) closes the specified FILE. Use the optional properties to specify closing properties.
officedoc(FILE, 'display', VISIBLEFLAG) displays the specified FILE in a corresponding MS Office application. If FILE is closed, then FILENAME should be used instead. VISIBLEFLAG is an optional flag determining visibility: true/1/'on' (=default) means display; false/0/'off'=hide. You can also specify this as an officedoc(...,'open',...) property. Note: PPT should remain visible or some features fail (ok in DOC/XLS)
officedoc(..., propName,propValue, ...) sets the property value(s) for the specified file action. Property specification order does not matter. PropNames are always case-insensitive, but in a few cases propValues might be case-sensitive. Some props are not supported by one or more doc types: such properties are simply ignored if irrelevant. 66 different properties are supported (more in future versions). Type "officedoc help props" to see the full list of supported properties.
officedoc comes a long way in enabling highly-customizable document output. However, there will always be certain unsupported Office features. Type "officedoc help examples" to see examples of accessing and using such features via direct COM calls.
officedoc('help',HELPTYPE) displays extended help on officedoc usage: - officedoc('help') displays this help section (same as "help officedoc") - officedoc('help','props') describes all the supported propNames - officedoc('help','examples') displays officedoc usage examples - officedoc('help','xls') displays only help relevant to XLS (or 'ppt','doc')