Office.File interface

Represents the document file associated with an Office Add-in.

Remarks

Access the File object with the AsyncResult.value property in the callback function passed to the Document.getFileAsync method.

Support details

A capital Y in the following matrix indicates that this interface is supported in the corresponding Office host application. An empty cell indicates that the Office host application doesn't support this interface.

For more information about Office host application and server requirements, see Requirements for running Office Add-ins.

Supported hosts, by platform

Office for Windows desktop Office Online (in browser) Office for iPad
PowerPoint Y Y Y
Word Y Y Y

Properties

size

Gets the document file size in bytes.

sliceCount

Gets the number of slices into which the file is divided.

Methods

closeAsync(callback)

Closes the document file.

getSliceAsync(sliceIndex, callback)

Returns the specified slice.

Property Details

size

Gets the document file size in bytes.

size: number;

Property Value

number

Remarks

Requirement SetsFile

sliceCount

Gets the number of slices into which the file is divided.

sliceCount: number;

Property Value

number

Method Details

closeAsync(callback)

Closes the document file.

closeAsync(callback?: (result: AsyncResult<void>) => void): void;

Parameters

callback
(result: AsyncResult<void>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult.

Returns

void

Remarks

Requirement SetsFile

No more than two documents are allowed to be in memory; otherwise the Document.getFileAsync operation will fail. Use the File.closeAsync method to close the file when you are finished working with it.

In the callback function passed to the closeAsync method, you can use the properties of the AsyncResult object to return the following information.

Property Use to...
AsyncResult.value Always returns undefined because there is no object or data to retrieve.
AsyncResult.status Determine the success or failure of the operation.
AsyncResult.error Access an Error object that provides error information if the operation failed.
AsyncResult.asyncContext A user-defined item of any type that is returned in the AsyncResult object without being altered.

getSliceAsync(sliceIndex, callback)

Returns the specified slice.

getSliceAsync(sliceIndex: number, callback?: (result: AsyncResult<Office.Slice>) => void): void;

Parameters

sliceIndex
number

Specifies the zero-based index of the slice to be retrieved. Required.

callback
(result: AsyncResult<Office.Slice>) => void

Optional. A function that is invoked when the callback returns, whose only parameter is of type Office.AsyncResult. The value property of the result is the Office.Slice object.

Returns

void

Remarks

Requirement SetsFile

In the callback function passed to the getSliceAsync method, you can use the properties of the AsyncResult object to return the following information.

Property Use to...
AsyncResult.value Access the Slice object.
AsyncResult.status Determine the success or failure of the operation.
AsyncResult.error Access an Error object that provides error information if the operation failed.
AsyncResult.asyncContext A user-defined item of any type that is returned in the AsyncResult object without being altered.