-
Notifications
You must be signed in to change notification settings - Fork 64
/
office.file.yml
168 lines (146 loc) · 6.76 KB
/
office.file.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
### YamlMime:TSType
name: Office.File
uid: 'office!Office.File:interface'
package: office!
fullName: Office.File
summary: 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.
isPreview: false
isDeprecated: false
type: interface
properties:
- name: size
uid: 'office!Office.File#size:member'
package: office!
fullName: size
summary: Gets the document file size in bytes.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'size: number;'
return:
type: number
- name: sliceCount
uid: 'office!Office.File#sliceCount:member'
package: office!
fullName: sliceCount
summary: Gets the number of slices into which the file is divided.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'sliceCount: number;'
return:
type: number
methods:
- name: closeAsync(callback)
uid: 'office!Office.File#closeAsync:member(1)'
package: office!
fullName: closeAsync(callback)
summary: Closes the document file.
remarks: >-
**Requirement set**:
[File](https://learn.microsoft.com/javascript/api/requirement-sets/common/office-add-in-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.
<table> <tr> <th>Property</th> <th>Use</th> </tr> <tr> <td><code>AsyncResult.value</code></td> <td>Always returns
<code>undefined</code> because there's no object or data to retrieve.</td> </tr> <tr>
<td><code>AsyncResult.status</code></td> <td>Determine the success or failure of the operation.</td> </tr> <tr>
<td><code>AsyncResult.error</code></td> <td>Access an Error object that provides error information if the
operation failed.</td> </tr> <tr> <td><code>AsyncResult.asyncContext</code></td> <td>Define an item of any type
that's returned in the AsyncResult object without being altered.</td> </tr> </table>
isPreview: false
isDeprecated: false
syntax:
content: 'closeAsync(callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: callback
description: >-
Optional. A function that is invoked when the callback returns, whose only parameter is of type
[Office.AsyncResult](xref:office!Office.AsyncResult:interface)<!-- -->.
type: '(result: <xref uid="office!Office.AsyncResult:interface" /><void>) => void'
return:
type: void
description: ''
- name: 'getSliceAsync(sliceIndex, callback)'
uid: 'office!Office.File#getSliceAsync:member(1)'
package: office!
fullName: 'getSliceAsync(sliceIndex, callback)'
summary: Returns the specified slice.
remarks: >-
**Requirement set**:
[File](https://learn.microsoft.com/javascript/api/requirement-sets/common/office-add-in-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.
<table> <tr> <th>Property</th> <th>Use</th> </tr> <tr> <td><code>AsyncResult.value</code></td> <td>Access the
Slice object.</td> </tr> <tr> <td><code>AsyncResult.status</code></td> <td>Determine the success or failure of the
operation.</td> </tr> <tr> <td><code>AsyncResult.error</code></td> <td>Access an Error object that provides error
information if the operation failed.</td> </tr> <tr> <td><code>AsyncResult.asyncContext</code></td> <td>Define an
item of any type that's returned in the AsyncResult object without being altered.</td> </tr> </table>
#### Examples
```TypeScript
// This sample shows how to get all the slices of a file.
// The asynchronous operation returns a Promise so it can be awaited.
private getAllSlices(file: any): Promise<any> {
const self = this;
let isError = false;
return new Promise(async (resolve, reject) => {
let documentFileData = [];
for (let sliceIndex = 0; (sliceIndex < file.sliceCount) && !isError; sliceIndex++) {
const sliceReadPromise = new Promise((sliceResolve, sliceReject) => {
file.getSliceAsync(sliceIndex, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
documentFileData = documentFileData.concat(asyncResult.value.data);
sliceResolve({
IsSuccess: true,
Data: documentFileData
});
} else {
file.closeAsync();
sliceReject({
IsSuccess: false,
ErrorMessage: `Error in reading the slice: ${sliceIndex} of the document`
});
}
});
});
await sliceReadPromise.catch((error) => {
isError = true;
});
}
if (isError || !documentFileData.length) {
reject('Error while reading document. Please try it again.');
return;
}
file.closeAsync();
resolve({
IsSuccess: true,
Data: documentFileData
});
});
}
```
isPreview: false
isDeprecated: false
syntax:
content: 'getSliceAsync(sliceIndex: number, callback?: (result: AsyncResult<Office.Slice>) => void): void;'
parameters:
- id: sliceIndex
description: Specifies the zero-based index of the slice to be retrieved. Required.
type: number
- id: callback
description: >-
Optional. A function that is invoked when the callback returns, whose only parameter is of type
[Office.AsyncResult](xref:office!Office.AsyncResult:interface)<!-- -->. The `value` property of the result
is the [Office.Slice](xref:office!Office.Slice:interface) object.
type: >-
(result: <xref uid="office!Office.AsyncResult:interface" /><<xref uid="office!Office.Slice:interface"
/>>) => void
return:
type: void
description: ''