Options

This is a collection of key/value pairs separated by a colon.
The key is the name of the parameter.
The value is the data that you want to use for that parameter.


Example - Document.getSelectedDataAsync

Office.context.document.getSelectedDataAsync(Office.CoercionType _coerciontype 
                                             [, Object _options]
                                             [, function _callback])

_coerciontype - The type of data that you want to get.
_options - This is a collection of key/value pairs seperated by a colon.
_callback - This is invoked once the aysnchronous operation is complete.
The optional parameters for the getSelectedDataAsync are:

NameTypeDescription
valueFormatValueFormatSpecifies whether to return the result with its number of date values formatted or unformatted.
Office.ValueFormat.Formatted
Office.ValueFormat.Unformatted
filterTypeFilterTypeSpecifies whether to apply filtering when the data is returned.
asyncContextanySpecifies a user defined item that can be accessed from the asyncResult object.

Example - Document.setSelectedDataAsync

Office.context.document.setSelectedDataAsync(Object _data 
                                             [, Object _options]
                                             [, function _callback])

_data - This is the value that you want to set.
_options - This is a collection of key/value pairs separated by a colon.
_callback - This is invoked once the aysnchronous operation is complete.


Parameter / Value Pairs

The values can be any javascript data type: String, Number, Boolean, Object, Array, Null, undefined
Each function has a list of specific parameters that are available


AsyncMethod ( RequiredParameters , [ OptionalParameters ], CallbackFunction );

The common syntax for all "Async" methods follows this pattern:
All asynchronous methods support optional parameters, which are passed in as a JavaScript Object Notation (JSON) object that contains one or more optional parameters. The JSON object containing the optional parameters is an unordered collection of key-value pairs with the ":" character separating the key and the value. Each pair in the object is comma-separated, and the entire set of pairs is enclosed in braces. The key is the parameter name, and value is the value to pass for that parameter.
You can create the JSON object that contains optional parameters inline, or by creating an options object and passing that in as the options parameter.


The following example shows how to call to the Document.setSelectedDataAsync method by specifying optional parameters inline.

{coercionType: "html", asyncContext: 42}, function(asyncResult) 
{ write(asyncResult.status + " " + asyncResult.asyncContext); } )

function write(message){
    document.getElementById('message').innerText += message;
}

Note: You can specify optional parameters in any order in the JSON object as long as their names are specified correctly


Alternatively, you can create an object named options that specifies the optional parameters separately from the method call, and then pass the options object as the options argument.

var options = { 
    valueFormat: "unformatted",
    filterType: "all"
};

Here's another way of creating the options object.

options["ValueFormat"] = "unformatted"; 
options["FilterType"] = "all";

When using either of these methods, you can specify optional parameters in any order as long as their names are specified correctly.

options object. 
var options = {
   coercionType: "html",
   asyncContext: 42
};

document.setSelectedDataAsync(
    "html-body hello world body-html",
    options,
    function(asyncResult) {
        write(asyncResult.status + " " + asyncResult.asyncContext);
    }
)

function write(message){
    document.getElementById('message').innerText += message;
}

In both optional parameter examples, the callback parameter is specified as the last parameter (following the inline optional parameters, or following the options argument object). Alternatively, you can specify the callback parameter inside either the inline JSON object, or in the options object. However, you can pass the callback parameter in only one location: either in the options object (inline or created externally), or as the last parameter, but not both


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext