-
Notifications
You must be signed in to change notification settings - Fork 64
/
office.tablebinding.yml
994 lines (751 loc) · 43.6 KB
/
office.tablebinding.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
### YamlMime:TSType
name: Office.TableBinding
uid: 'office!Office.TableBinding:interface'
package: office!
fullName: Office.TableBinding
summary: 'Represents a binding in two dimensions of rows and columns, optionally with headers.'
remarks: >-
The TableBinding object inherits the `id` property, `type` property, `getDataAsync` method, and `setDataAsync` method
from the [Office.Binding](xref:office!Office.Binding:interface) object.
For Excel, note that after you establish a table binding, each new row a user adds to the table is automatically
included in the binding and rowCount increases.
isPreview: false
isDeprecated: false
type: interface
properties:
- name: columnCount
uid: 'office!Office.TableBinding#columnCount:member'
package: office!
fullName: columnCount
summary: 'Gets the number of columns in the TableBinding, as an integer value.'
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'columnCount: number;'
return:
type: number
description: |-
#### Examples
```TypeScript
function showBindingColumnCount() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Column: " + asyncResult.value.columnCount);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
```
- name: hasHeaders
uid: 'office!Office.TableBinding#hasHeaders:member'
package: office!
fullName: hasHeaders
summary: 'True, if the table has headers; otherwise false.'
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'hasHeaders: boolean;'
return:
type: boolean
description: |-
#### Examples
```TypeScript
function showBindingHasHeaders() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Binding has headers: " + asyncResult.value.hasHeaders);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
```
- name: rowCount
uid: 'office!Office.TableBinding#rowCount:member'
package: office!
fullName: rowCount
summary: 'Gets the number of rows in the TableBinding, as an integer value.'
remarks: >-
When you insert an empty table by selecting a single row in Excel on desktop and Excel on the web (using Table on
the Insert tab), both Office applications create a single row of headers followed by a single blank row. However,
if your add-in's script creates a binding for this newly inserted table (for example, by using the
[Office.Bindings](xref:office!Office.Bindings:interface)<!-- -->.addFromSelectionAsync method), and then checks
the value of the rowCount property, the value returned will differ depending whether the spreadsheet is open in
Excel on desktop or Excel on the web.
- In Excel on the desktop (i.e., Windows and Mac), rowCount will return 0 (the blank row following the headers
isn't counted).
- In Excel on the web, rowCount will return 1 (the blank row following the headers is counted).
You can work around this difference in your script by checking if rowCount == 1, and if so, then checking if the
row contains all empty strings.
#### Examples
```TypeScript
function showBindingRowCount() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
write("Rows: " + asyncResult.value.rowCount);
});
}
// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
```
isPreview: false
isDeprecated: false
syntax:
content: 'rowCount: number;'
return:
type: number
methods:
- name: 'addColumnsAsync(tableData, options, callback)'
uid: 'office!Office.TableBinding#addColumnsAsync:member(1)'
package: office!
fullName: 'addColumnsAsync(tableData, options, callback)'
summary: Adds the specified data to the table as additional columns.
remarks: >-
To add one or more columns specifying the values of the data and headers, pass a TableData object as the data
parameter. To add one or more columns specifying only the data, pass an array of arrays ("matrix") as the data
parameter.
The success or failure of an addColumnsAsync operation is atomic. That is, the entire add columns operation must
succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will
report failure):
- Each row in the array you pass as the data argument must have the same number of rows as the table being
updated. If not, the entire operation will fail.
- Each row and cell in the array must successfully add that row or cell to the table in the newly added columns.
If any row or cell fails to be set for any reason, the entire operation will fail.
- If you pass a TableData object as the data argument, the number of header rows must match that of the table
being updated.
Additional remark for Excel on the web: The total number of cells in the TableData object passed to the data
parameter can't exceed 20,000 in a single call to this method.
#### Examples
```TypeScript
// The following example adds a single column with three rows to a bound table with the id "myTable"
// by passing a TableData object as the data argument of the addColumnsAsync method. To succeed,
// the table being updated must have three rows.
// Add a column to a binding of type table by passing a TableData object.
function addColumns() {
const myTable = new Office.TableData();
myTable.headers = [["Cities"]];
myTable.rows = [["Berlin"], ["Roma"], ["Tokyo"]];
Office.context.document.bindings.getByIdAsync("myTable", function (result) {
result.value.addColumnsAsync(myTable);
});
}
// The following example adds a single column with three rows to a bound table with the id myTable
// by passing an array of arrays ("matrix") as the data argument of the addColumnsAsync method.
// To succeed, the table being updated must have three rows.
// Add a column to a binding of type table by passing an array of arrays.
function addColumns() {
const myTable = [["Berlin"], ["Roma"], ["Tokyo"]];
Office.context.document.bindings.getByIdAsync("myTable", function (result) {
result.value.addColumnsAsync(myTable);
});
}
```
isPreview: false
isDeprecated: false
syntax:
content: >-
addColumnsAsync(tableData: TableData | any[][], options?: Office.AsyncContextOptions, callback?: (result:
AsyncResult<void>) => void): void;
parameters:
- id: tableData
description: >-
An array of arrays ("matrix") or a TableData object that contains one or more columns of data to add to the
table. Required.
type: '<xref uid="office!Office.TableData:class" /> | any[][]'
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: 'addColumnsAsync(tableData, callback)'
uid: 'office!Office.TableBinding#addColumnsAsync:member(2)'
package: office!
fullName: 'addColumnsAsync(tableData, callback)'
summary: Adds the specified data to the table as additional columns.
remarks: >-
To add one or more columns specifying the values of the data and headers, pass a TableData object as the data
parameter. To add one or more columns specifying only the data, pass an array of arrays ("matrix") as the data
parameter.
The success or failure of an addColumnsAsync operation is atomic. That is, the entire add columns operation must
succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will
report failure):
- Each row in the array you pass as the data argument must have the same number of rows as the table being
updated. If not, the entire operation will fail.
- Each row and cell in the array must successfully add that row or cell to the table in the newly added columns.
If any row or cell fails to be set for any reason, the entire operation will fail.
- If you pass a TableData object as the data argument, the number of header rows must match that of the table
being updated.
Additional remark for Excel on the web: The total number of cells in the TableData object passed to the data
parameter can't exceed 20,000 in a single call to this method.
isPreview: false
isDeprecated: false
syntax:
content: 'addColumnsAsync(tableData: TableData | any[][], callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: tableData
description: >-
An array of arrays ("matrix") or a TableData object that contains one or more columns of data to add to the
table. Required.
type: '<xref uid="office!Office.TableData:class" /> | any[][]'
- 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: 'addRowsAsync(rows, options, callback)'
uid: 'office!Office.TableBinding#addRowsAsync:member(1)'
package: office!
fullName: 'addRowsAsync(rows, options, callback)'
summary: Adds the specified data to the table as additional rows.
remarks: >-
The success or failure of an addRowsAsync operation is atomic. That is, the entire add columns operation must
succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will
report failure):
- Each row in the array you pass as the data argument must have the same number of columns as the table being
updated. If not, the entire operation will fail.
- Each column and cell in the array must successfully add that column or cell to the table in the newly added
rows. If any column or cell fails to be set for any reason, the entire operation will fail.
- If you pass a TableData object as the data argument, the number of header rows must match that of the table
being updated.
Additional remark for Excel on the web: The total number of cells in the TableData object passed to the data
parameter can't exceed 20,000 in a single call to this method.
#### Examples
```TypeScript
function addRowsToTable() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
const binding = asyncResult.value;
binding.addRowsAsync([["6", "k"], ["7", "j"]]);
});
}
```
isPreview: false
isDeprecated: false
syntax:
content: >-
addRowsAsync(rows: TableData | any[][], options?: Office.AsyncContextOptions, callback?: (result:
AsyncResult<void>) => void): void;
parameters:
- id: rows
description: >-
An array of arrays ("matrix") or a TableData object that contains one or more rows of data to add to the
table. Required.
type: '<xref uid="office!Office.TableData:class" /> | any[][]'
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: 'addRowsAsync(rows, callback)'
uid: 'office!Office.TableBinding#addRowsAsync:member(2)'
package: office!
fullName: 'addRowsAsync(rows, callback)'
summary: Adds the specified data to the table as additional rows.
remarks: >-
The success or failure of an addRowsAsync operation is atomic. That is, the entire add columns operation must
succeed, or it will be completely rolled back (and the AsyncResult.status property returned to the callback will
report failure):
- Each row in the array you pass as the data argument must have the same number of columns as the table being
updated. If not, the entire operation will fail.
- Each column and cell in the array must successfully add that column or cell to the table in the newly added
rows. If any column or cell fails to be set for any reason, the entire operation will fail.
- If you pass a TableData object as the data argument, the number of header rows must match that of the table
being updated.
Additional remark for Excel on the web: The total number of cells in the TableData object passed to the data
parameter can't exceed 20,000 in a single call to this method.
isPreview: false
isDeprecated: false
syntax:
content: 'addRowsAsync(rows: TableData | any[][], callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: rows
description: >-
An array of arrays ("matrix") or a TableData object that contains one or more rows of data to add to the
table. Required.
type: '<xref uid="office!Office.TableData:class" /> | any[][]'
- 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: 'clearFormatsAsync(options, callback)'
uid: 'office!Office.TableBinding#clearFormatsAsync:member(1)'
package: office!
fullName: 'clearFormatsAsync(options, callback)'
summary: Clears formatting on the bound table.
remarks: >-
See [Format tables in add-ins for
Excel](https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-tables#format-a-table) for more
information.
#### Examples
```TypeScript
// The following example shows how to clear the formatting of the bound table with an ID of "myBinding":
Office.select("bindings#myBinding").clearFormatsAsync();
```
isPreview: false
isDeprecated: false
syntax:
content: 'clearFormatsAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: clearFormatsAsync(callback)
uid: 'office!Office.TableBinding#clearFormatsAsync:member(2)'
package: office!
fullName: clearFormatsAsync(callback)
summary: Clears formatting on the bound table.
remarks: >-
See [Format tables in add-ins for
Excel](https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-tables#format-a-table) for more
information.
isPreview: false
isDeprecated: false
syntax:
content: 'clearFormatsAsync(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: 'deleteAllDataValuesAsync(options, callback)'
uid: 'office!Office.TableBinding#deleteAllDataValuesAsync:member(1)'
package: office!
fullName: 'deleteAllDataValuesAsync(options, callback)'
summary: 'Deletes all non-header rows and their values in the table, shifting appropriately for the Office application.'
remarks: |-
In Excel, if the table has no header row, this method will delete the table itself.
#### Examples
```TypeScript
function deleteAllRowsFromTable() {
Office.context.document.bindings.getByIdAsync("myBinding", function (asyncResult) {
const binding = asyncResult.value;
binding.deleteAllDataValuesAsync();
});
}
```
isPreview: false
isDeprecated: false
syntax:
content: >-
deleteAllDataValuesAsync(options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>) => void):
void;
parameters:
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: deleteAllDataValuesAsync(callback)
uid: 'office!Office.TableBinding#deleteAllDataValuesAsync:member(2)'
package: office!
fullName: deleteAllDataValuesAsync(callback)
summary: 'Deletes all non-header rows and their values in the table, shifting appropriately for the Office application.'
remarks: 'In Excel, if the table has no header row, this method will delete the table itself.'
isPreview: false
isDeprecated: false
syntax:
content: 'deleteAllDataValuesAsync(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: 'getFormatsAsync(cellReference, formats, options, callback)'
uid: 'office!Office.TableBinding#getFormatsAsync:member(1)'
package: office!
fullName: 'getFormatsAsync(cellReference, formats, options, callback)'
summary: Gets the formatting on specified items in the table.
remarks: >-
**Returned format structure**
Each JavaScript object in the return value array has this form: `{cells:{ cell_range }, format:{ format_definition
}}`
The `cells:` property specifies the range you want format using one of the following values.
**Supported ranges in cells property**
<table> <tr> <th><code>cells</code> range settings</th> <th>Description</th> </tr> <tr> <td><code>{<!-- -->row:
n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth row of data in the table.</td> </tr> <tr>
<td><code>{<!-- -->column: n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth column of data
in the table.</td> </tr> <tr> <td><code>{<!-- -->row: i, column: j<!-- -->}</code></td> <td>Specifies the single
cell that's the ith row and jth column of the table.</td> </tr> <tr> <td><code>Office.Table.All</code></td>
<td>Specifies the entire table, including column headers, data, and totals (if any).</td> </tr> <tr>
<td><code>Office.Table.Data</code></td> <td>Specifies only the data in the table (no headers and totals).</td>
</tr> <tr> <td><code>Office.Table.Headers</code></td> <td>Specifies only the header row.</td> </tr> </table>
The `format:` property specifies values that correspond to a subset of the settings available in the Format Cells
dialog box in Excel (Open the context menu (right-click or select and hold) then select **Format Cells**, or
**Home** > **Format** > **Format Cells**).
isPreview: false
isDeprecated: false
syntax:
content: >-
getFormatsAsync(cellReference?: any, formats?: any[], options?: Office.AsyncContextOptions, callback?: (result:
AsyncResult< Array<{ cells: any, format: any}>>) => void): void;
parameters:
- id: cellReference
description: An object literal containing name-value pairs that specify the range of cells to get formatting from.
type: any
- id: formats
description: An array specifying the format properties to get.
type: 'any[]'
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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 an array containing one or more JavaScript objects specifying the formatting of their corresponding
cells.
type: >-
(result: <xref uid="office!Office.AsyncResult:interface" />< Array<{ cells: any, format: any}>>)
=> void
return:
type: void
description: ''
- name: 'getFormatsAsync(cellReference, formats, callback)'
uid: 'office!Office.TableBinding#getFormatsAsync:member(2)'
package: office!
fullName: 'getFormatsAsync(cellReference, formats, callback)'
summary: Gets the formatting on specified items in the table.
remarks: >-
**Returned format structure**
Each JavaScript object in the return value array has this form: `{cells:{ cell_range }, format:{ format_definition
}}`
The `cells:` property specifies the range you want format using one of the following values.
**Supported ranges in cells property**
<table> <tr> <th><code>cells</code> range settings</th> <th>Description</th> </tr> <tr> <td><code>{<!-- -->row:
n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth row of data in the table.</td> </tr> <tr>
<td><code>{<!-- -->column: n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth column of data
in the table.</td> </tr> <tr> <td><code>{<!-- -->row: i, column: j<!-- -->}</code></td> <td>Specifies the single
cell that's the ith row and jth column of the table.</td> </tr> <tr> <td><code>Office.Table.All</code></td>
<td>Specifies the entire table, including column headers, data, and totals (if any).</td> </tr> <tr>
<td><code>Office.Table.Data</code></td> <td>Specifies only the data in the table (no headers and totals).</td>
</tr> <tr> <td><code>Office.Table.Headers</code></td> <td>Specifies only the header row.</td> </tr> </table>
The `format:` property specifies values that correspond to a subset of the settings available in the Format Cells
dialog box in Excel (Open the context menu (right-click or select and hold) then select **Format Cells**, or
**Home** > **Format** > **Format Cells**).
isPreview: false
isDeprecated: false
syntax:
content: >-
getFormatsAsync(cellReference?: any, formats?: any[], callback?: (result: AsyncResult< Array<{ cells: any,
format: any}>>) => void): void;
parameters:
- id: cellReference
description: An object literal containing name-value pairs that specify the range of cells to get formatting from.
type: any
- id: formats
description: An array specifying the format properties to get.
type: 'any[]'
- 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 an array containing one or more JavaScript objects specifying the formatting of their corresponding
cells.
type: >-
(result: <xref uid="office!Office.AsyncResult:interface" />< Array<{ cells: any, format: any}>>)
=> void
return:
type: void
description: ''
- name: 'setFormatsAsync(cellFormat, options, callback)'
uid: 'office!Office.TableBinding#setFormatsAsync:member(1)'
package: office!
fullName: 'setFormatsAsync(cellFormat, options, callback)'
summary: Sets formatting on specified items and data in the table.
remarks: >-
**Specifying the cellFormat parameter**
Use the cellFormat parameter to set or change cell formatting values, such as width, height, font, background,
alignment, and so on. The value you pass as the cellFormat parameter is an array that contains a list of one or
more JavaScript objects that specify which cells to target (`cells:`<!-- -->) and the formats (`format:`<!-- -->)
to apply to them.
Each JavaScript object in the cellFormat array has this form: `{cells:{ cell_range }, format:{ format_definition
}}`
The `cells:` property specifies the range you want format using one of the following values.
**Supported ranges in cells property**
<table> <tr> <th><code>cells</code> range settings</th> <th>Description</th> </tr> <tr> <td><code>{<!-- -->row:
n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth row of data in the table.</td> </tr> <tr>
<td><code>{<!-- -->column: n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth column of data
in the table.</td> </tr> <tr> <td><code>{<!-- -->row: i, column: j<!-- -->}</code></td> <td>Specifies the single
cell that's the ith row and jth column of the table.</td> </tr> <tr> <td><code>Office.Table.All</code></td>
<td>Specifies the entire table, including column headers, data, and totals (if any).</td> </tr> <tr>
<td><code>Office.Table.Data</code></td> <td>Specifies only the data in the table (no headers and totals).</td>
</tr> <tr> <td><code>Office.Table.Headers</code></td> <td>Specifies only the header row.</td> </tr> </table>
The `format:` property specifies values that correspond to a subset of the settings available in the Format Cells
dialog box in Excel (Open the context menu (right-click or select and hold) then select **Format Cells**, or
**Home** > **Format** > **Format Cells**).
You specify the value of the `format:` property as a list of one or more property name - value pairs in a
JavaScript object literal. The property name specifies the name of the formatting property to set, and value
specifies the property value. You can specify multiple values for a given format, such as both a font's color and
size.
Here's three `format:` property value examples:
`//Set cells: font color to green and size to 15 points.`
`format: {fontColor : "green", fontSize : 15}`
`//Set cells: border to dotted blue.`
`format: {borderStyle: "dotted", borderColor: "blue"}`
`//Set cells: background to red and alignment to centered.`
`format: {backgroundColor: "red", alignHorizontal: "center"}`
You can specify number formats by specifying the number formatting "code" string in the `numberFormat:` property.
The number format strings you can specify correspond to those you can set in Excel using the Custom category on
the Number tab of the Format Cells dialog box. This example shows how to format a number as a percentage with two
decimal places:
`format: {numberFormat:"0.00%"}`
For more detail, see how to [Create a custom number
format](https://support.microsoft.com/office/78f2a361-936b-4c03-8772-09fab54be7f4)<!-- -->.
To set formatting on tables when writing data, use the tableOptions and cellFormat optional parameters of the
`Document.setSelectedDataAsync` or `TableBinding.setDataAsync` methods.
Setting formatting with the optional parameters of the `Document.setSelectedDataAsync` and
`TableBinding.setDataAsync` methods only works to set formatting when writing data the first time. To make
formatting changes after writing data, use the following methods.
- To update cell formatting, such as font color and style, use the `TableBinding.setFormatsAsync` method (this
method).
- To update table options, such as banded rows and filter buttons, use the `TableBinding.setTableOptions` method.
- To clear formatting, use the `TableBinding.clearFormats` method.
For more details and examples, see [How to format tables in add-ins for
Excel](https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-tables#format-a-table)<!-- -->.
#### Examples
```TypeScript
// Specifying a single target
// The following example shows a cellFormat value that sets the font color of the header row to red.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: Office.Table.Headers, format: {fontColor: "red"}}],
function (asyncResult){});
// Specifying multiple targets
// The setFormatsAsync method can support formatting multiple targets within the bound table in a
// single function call. To do that, you pass a list of objects in the cellFormat array
// for each target that you want to format.
// For example, the following line of code will set the font color of the first row yellow,
// and the fourth cell in the third row to have a white border and bold text.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: {row: 1}, format: {fontColor: "yellow"}},
{cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}],
function (asyncResult){});
// Additional remarks for Excel Online
// The number of formatting groups passed to the cellFormat parameter can't exceed 100.
// A single formatting group consists of a set of formatting applied to a specified range of cells.
// For example, the following call passes two formatting groups to cellFormat.
Office.select("bindings#myBinding").setFormatsAsync(
[{cells: {row: 1}, format: {fontColor: "yellow"}},
{cells: {row: 3, column: 4}, format: {borderColor: "white", fontStyle: "bold"}}],
function (asyncResult){});
```
isPreview: false
isDeprecated: false
syntax:
content: >-
setFormatsAsync(cellFormat: any[], options?: Office.AsyncContextOptions, callback?: (result: AsyncResult<void>)
=> void): void;
parameters:
- id: cellFormat
description: >-
An array that contains one or more JavaScript objects that specify which cells to target and the formatting
to apply to them.
type: 'any[]'
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: 'setFormatsAsync(cellFormat, callback)'
uid: 'office!Office.TableBinding#setFormatsAsync:member(2)'
package: office!
fullName: 'setFormatsAsync(cellFormat, callback)'
summary: Sets formatting on specified items and data in the table.
remarks: >-
**Specifying the cellFormat parameter**
Use the cellFormat parameter to set or change cell formatting values, such as width, height, font, background,
alignment, and so on. The value you pass as the cellFormat parameter is an array that contains a list of one or
more JavaScript objects that specify which cells to target (`cells:`<!-- -->) and the formats (`format:`<!-- -->)
to apply to them.
Each JavaScript object in the cellFormat array has this form: `{cells:{ cell_range }, format:{ format_definition
}}`
The `cells:` property specifies the range you want format using one of the following values.
**Supported ranges in cells property**
<table> <tr> <th><code>cells</code> range settings</th> <th>Description</th> </tr> <tr> <td><code>{<!-- -->row:
n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth row of data in the table.</td> </tr> <tr>
<td><code>{<!-- -->column: n<!-- -->}</code></td> <td>Specifies the range that's the zero-based nth column of data
in the table.</td> </tr> <tr> <td><code>{<!-- -->row: i, column: j<!-- -->}</code></td> <td>Specifies the single
cell that's the ith row and jth column of the table.</td> </tr> <tr> <td><code>Office.Table.All</code></td>
<td>Specifies the entire table, including column headers, data, and totals (if any).</td> </tr> <tr>
<td><code>Office.Table.Data</code></td> <td>Specifies only the data in the table (no headers and totals).</td>
</tr> <tr> <td><code>Office.Table.Headers</code></td> <td>Specifies only the header row.</td> </tr> </table>
The `format:` property specifies values that correspond to a subset of the settings available in the Format Cells
dialog box in Excel (Open the context menu (right-click or select and hold) then select **Format Cells**, or
**Home** > **Format** > **Format Cells**).
You specify the value of the `format:` property as a list of one or more property name - value pairs in a
JavaScript object literal. The property name specifies the name of the formatting property to set, and value
specifies the property value. You can specify multiple values for a given format, such as both a font's color and
size.
Here's three `format:` property value examples:
`//Set cells: font color to green and size to 15 points.`
`format: {fontColor : "green", fontSize : 15}`
`//Set cells: border to dotted blue.`
`format: {borderStyle: "dotted", borderColor: "blue"}`
`//Set cells: background to red and alignment to centered.`
`format: {backgroundColor: "red", alignHorizontal: "center"}`
You can specify number formats by specifying the number formatting "code" string in the `numberFormat:` property.
The number format strings you can specify correspond to those you can set in Excel using the Custom category on
the Number tab of the Format Cells dialog box. This example shows how to format a number as a percentage with two
decimal places:
`format: {numberFormat:"0.00%"}`
For more detail, see how to [Create a custom number
format](https://support.microsoft.com/office/78f2a361-936b-4c03-8772-09fab54be7f4)<!-- -->.
To set formatting on tables when writing data, use the tableOptions and cellFormat optional parameters of the
`Document.setSelectedDataAsync` or `TableBinding.setDataAsync` methods.
Setting formatting with the optional parameters of the `Document.setSelectedDataAsync` and
`TableBinding.setDataAsync` methods only works to set formatting when writing data the first time. To make
formatting changes after writing data, use the following methods.
- To update cell formatting, such as font color and style, use the `TableBinding.setFormatsAsync` method (this
method).
- To update table options, such as banded rows and filter buttons, use the `TableBinding.setTableOptions` method.
- To clear formatting, use the `TableBinding.clearFormats` method.
For more details and examples, see [How to format tables in add-ins for
Excel](https://learn.microsoft.com/office/dev/add-ins/excel/excel-add-ins-tables#format-a-table)<!-- -->.
isPreview: false
isDeprecated: false
syntax:
content: 'setFormatsAsync(cellFormat: any[], callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: cellFormat
description: >-
An array that contains one or more JavaScript objects that specify which cells to target and the formatting
to apply to them.
type: 'any[]'
- 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: 'setTableOptionsAsync(tableOptions, options, callback)'
uid: 'office!Office.TableBinding#setTableOptionsAsync:member(1)'
package: office!
fullName: 'setTableOptionsAsync(tableOptions, options, callback)'
summary: Updates table formatting options on the bound table.
remarks: >-
**Requirement set**: [Not in a
set](https://learn.microsoft.com/javascript/api/requirement-sets/common/office-add-in-requirement-sets#methods-that-arent-part-of-a-requirement-set)
In the callback function passed to the goToByIdAsync 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 data or object to retrieve when setting formats.</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
// The following example shows how to:
// 1. Create an object literal that specifies the table formatting options to update on the bound table.
// 2. Call setTableOptions on a previously bound table (with an id of myBinding) passing the object
// with formatting setting as the tableOptions parameter.
function updateTableFormatting(){
const tableOptions = {bandedRows: true, filterButton: false, style: "TableStyleMedium3"};
Office.select("bindings#myBinding").setTableOptionsAsync(tableOptions, function(asyncResult){});
}
```
isPreview: false
isDeprecated: false
syntax:
content: >-
setTableOptionsAsync(tableOptions: any, options?: Office.AsyncContextOptions, callback?: (result:
AsyncResult<void>) => void): void;
parameters:
- id: tableOptions
description: An object literal containing a list of property name-value pairs that define the table options to apply.
type: any
- id: options
description: 'Provides an option for preserving context data of any type, unchanged, for use in a callback.'
type: '<xref uid="office!Office.AsyncContextOptions:interface" />'
- 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: 'setTableOptionsAsync(tableOptions, callback)'
uid: 'office!Office.TableBinding#setTableOptionsAsync:member(2)'
package: office!
fullName: 'setTableOptionsAsync(tableOptions, callback)'
summary: Updates table formatting options on the bound table.
remarks: >-
**Requirement set**: [Not in a
set](https://learn.microsoft.com/javascript/api/requirement-sets/common/office-add-in-requirement-sets#methods-that-arent-part-of-a-requirement-set)
In the callback function passed to the goToByIdAsync 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 data or object to retrieve when setting formats.</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: 'setTableOptionsAsync(tableOptions: any, callback?: (result: AsyncResult<void>) => void): void;'
parameters:
- id: tableOptions
description: An object literal containing a list of property name-value pairs that define the table options to apply.
type: any
- 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: ''
extends: '<xref uid="office!Office.Binding:interface" />'