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 | Office for Mac | |
---|---|---|---|---|
Excel | Y | Y | Y | Y |
PowerPoint | Y | Y | Y | Y |
Word | Y | Y | Y | Y |
Properties
size | Gets the document file size in bytes. |
slice |
Gets the number of slices into which the file is divided. |
Methods
close |
Closes the document file. |
get |
Returns the specified slice. |
Property Details
size
Gets the document file size in bytes.
size: number;
Property Value
Remarks
Requirement Sets | File |
sliceCount
Gets the number of slices into which the file is divided.
sliceCount: number;
Property Value
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
Remarks
Requirement Sets | File |
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
- 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
Remarks
Requirement Sets | File |
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. |
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...