/
excelscript.worksheet.yml
1954 lines (1855 loc) · 71.8 KB
/
excelscript.worksheet.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
995
996
997
998
999
1000
### YamlMime:TSType
name: ExcelScript.Worksheet
uid: 'ExcelScript!ExcelScript.Worksheet:interface'
package: ExcelScript!
fullName: ExcelScript.Worksheet
summary: 'An Excel worksheet is a grid of cells. It can contain data, tables, charts, etc.'
remarks: |-
#### Examples
```TypeScript
/**
* This script creates a new worksheet named "Plum" and sets its tab color to purple.
*/
function main(workbook: ExcelScript.Workbook) {
const newSheet = workbook.addWorksheet("Plum")
newSheet.setTabColor("purple");
}
```
isPreview: false
isDeprecated: false
type: interface
methods:
- name: activate()
uid: 'ExcelScript!ExcelScript.Worksheet#activate:member(1)'
package: ExcelScript!
fullName: activate()
summary: Activate the worksheet in the Excel UI.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'activate(): void;'
return:
type: void
description: |-
#### Examples
```TypeScript
/**
* This script switches the active view to a worksheet named "Data", if it exists.
*/
function main(workbook: ExcelScript.Workbook) {
// Check if the "Data" worksheet exists.
let dataWorksheet = workbook.getWorksheet("Data");
if (dataWorksheet) {
// Switch to the "Data" worksheet.
dataWorksheet.activate();
} else {
console.log(`No worksheet named "Data" in this workbook.`);
}
}
```
- name: 'addChart(type, sourceData, seriesBy)'
uid: 'ExcelScript!ExcelScript.Worksheet#addChart:member(1)'
package: ExcelScript!
fullName: 'addChart(type, sourceData, seriesBy)'
summary: Creates a new chart.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addChart(
type: ChartType,
sourceData: Range,
seriesBy?: ChartSeriesBy
): Chart;
parameters:
- id: type
description: Represents the type of a chart. See `ExcelScript.ChartType` for details.
type: '<xref uid="ExcelScript!ExcelScript.ChartType:enum" />'
- id: sourceData
description: The `Range` object corresponding to the source data.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" />'
- id: seriesBy
description: >-
Optional. Specifies the way columns or rows are used as data series on the chart. See
`ExcelScript.ChartSeriesBy` for details.
type: '<xref uid="ExcelScript!ExcelScript.ChartSeriesBy:enum" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Chart:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This sample creates a column-clustered chart based on the current worksheet's data.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the current worksheet.
let selectedSheet = workbook.getActiveWorksheet();
// Get the data range.
let range = selectedSheet.getUsedRange();
// Insert a chart using the data on the current worksheet.
let chart = selectedSheet.addChart(ExcelScript.ChartType.columnClustered, range);
// Name the chart for easy access in other scripts.
chart.setName("ColumnChart");
}
```
- name: 'addComment(cellAddress, content, contentType)'
uid: 'ExcelScript!ExcelScript.Worksheet#addComment:member(1)'
package: ExcelScript!
fullName: 'addComment(cellAddress, content, contentType)'
summary: >-
Creates a new comment with the given content on the given cell. An `InvalidArgument` error is thrown if the
provided range is larger than one cell.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addComment(
cellAddress: Range | string,
content: CommentRichContent | string,
contentType?: ContentType
): Comment;
parameters:
- id: cellAddress
description: >-
The cell to which the comment is added. This can be a `Range` object or a string. If it's a string, it must
contain the full address, including the sheet name. An `InvalidArgument` error is thrown if the provided
range is larger than one cell.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
- id: content
description: >-
The comment's content. This can be either a string or `CommentRichContent` object. Strings are used for
plain text. `CommentRichContent` objects allow for other comment features, such as mentions.
type: '<xref uid="ExcelScript!ExcelScript.CommentRichContent:interface" /> | string'
- id: contentType
description: >-
Optional. The type of content contained within the comment. The default value is enum
`ContentType.Plain`<!-- -->.
type: '<xref uid="ExcelScript!ExcelScript.ContentType:enum" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Comment:interface" />'
description: ''
- name: addGeometricShape(geometricShapeType)
uid: 'ExcelScript!ExcelScript.Worksheet#addGeometricShape:member(1)'
package: ExcelScript!
fullName: addGeometricShape(geometricShapeType)
summary: Adds a geometric shape to the worksheet. Returns a `Shape` object that represents the new shape.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addGeometricShape(geometricShapeType: GeometricShapeType): Shape;'
parameters:
- id: geometricShapeType
description: Represents the type of the geometric shape. See `ExcelScript.GeometricShapeType` for details.
type: '<xref uid="ExcelScript!ExcelScript.GeometricShapeType:enum" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Shape:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script creates a hexagon shape on the current worksheet.
*/
function main(workbook: ExcelScript.Workbook) {
const currentSheet = workbook.getActiveWorksheet();
const hexagon: ExcelScript.Shape =
currentSheet.addGeometricShape(ExcelScript.GeometricShapeType.hexagon);
// Set the hexagon size to 40x40 pixels.
hexagon.setHeight(40);
hexagon.setWidth(40);
// Position the hexagon at [100,100] pixels.
hexagon.setLeft(100);
hexagon.setTop(100);
}
```
- name: addGroup(values)
uid: 'ExcelScript!ExcelScript.Worksheet#addGroup:member(1)'
package: ExcelScript!
fullName: addGroup(values)
summary: >-
Groups a subset of shapes in this collection's worksheet. Returns a `Shape` object that represents the new group
of shapes.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addGroup(values: Array<string | Shape>): Shape;'
parameters:
- id: values
description: An array of shape IDs or shape objects.
type: 'Array<string | <xref uid="ExcelScript!ExcelScript.Shape:interface" />>'
return:
type: '<xref uid="ExcelScript!ExcelScript.Shape:interface" />'
description: ''
- name: addHorizontalPageBreak(pageBreakRange)
uid: 'ExcelScript!ExcelScript.Worksheet#addHorizontalPageBreak:member(1)'
package: ExcelScript!
fullName: addHorizontalPageBreak(pageBreakRange)
summary: Adds a page break before the top-left cell of the range specified.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addHorizontalPageBreak(pageBreakRange: Range | string): PageBreak;'
parameters:
- id: pageBreakRange
description: The range immediately after the page break to be added.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
return:
type: '<xref uid="ExcelScript!ExcelScript.PageBreak:interface" />'
description: ''
- name: addImage(base64ImageString)
uid: 'ExcelScript!ExcelScript.Worksheet#addImage:member(1)'
package: ExcelScript!
fullName: addImage(base64ImageString)
summary: >-
Creates an image from a base64-encoded string and adds it to the worksheet. Returns the `Shape` object that
represents the new image.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addImage(base64ImageString: string): Shape;'
parameters:
- id: base64ImageString
description: A base64-encoded string representing an image in either JPEG or PNG format.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.Shape:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This sample copies an image from a URL.
* This could be used to copy photos that a colleague stored in a shared folder to a related workbook.
*/
async function main(workbook: ExcelScript.Workbook) {
// Fetch the image from a URL.
const link = "https://raw.githubusercontent.com/OfficeDev/office-scripts-docs/master/docs/images/git-octocat.png";
const response = await fetch(link);
// Store the response as an ArrayBuffer, since it is a raw image file.
const data = await response.arrayBuffer();
// Convert the image data into a base64-encoded string.
const image = convertToBase64(data);
// Add the image to the current worksheet.
workbook.getActiveWorksheet().addImage(image);
}
/**
* Converts an ArrayBuffer containing a .png image into a base64-encoded string.
*/
function convertToBase64(input: ArrayBuffer) {
const uInt8Array = new Uint8Array(input);
const count = uInt8Array.length;
// Allocate the necessary space up front.
const charCodeArray = new Array<string>(count)
// Convert every entry in the array to a character.
for (let i = count; i >= 0; i--) {
charCodeArray[i] = String.fromCharCode(uInt8Array[i]);
}
// Convert the characters to base64.
const base64 = btoa(charCodeArray.join(''));
return base64;
}
```
- name: 'addLine(startLeft, startTop, endLeft, endTop, connectorType)'
uid: 'ExcelScript!ExcelScript.Worksheet#addLine:member(1)'
package: ExcelScript!
fullName: 'addLine(startLeft, startTop, endLeft, endTop, connectorType)'
summary: Adds a line to worksheet. Returns a `Shape` object that represents the new line.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addLine(
startLeft: number,
startTop: number,
endLeft: number,
endTop: number,
connectorType?: ConnectorType
): Shape;
parameters:
- id: startLeft
description: 'The distance, in points, from the start of the line to the left side of the worksheet.'
type: number
- id: startTop
description: 'The distance, in points, from the start of the line to the top of the worksheet.'
type: number
- id: endLeft
description: 'The distance, in points, from the end of the line to the left of the worksheet.'
type: number
- id: endTop
description: 'The distance, in points, from the end of the line to the top of the worksheet.'
type: number
- id: connectorType
description: Represents the connector type. See `ExcelScript.ConnectorType` for details.
type: '<xref uid="ExcelScript!ExcelScript.ConnectorType:enum" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Shape:interface" />'
description: ''
- name: 'addNamedItem(name, reference, comment)'
uid: 'ExcelScript!ExcelScript.Worksheet#addNamedItem:member(1)'
package: ExcelScript!
fullName: 'addNamedItem(name, reference, comment)'
summary: Adds a new name to the collection of the given scope.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addNamedItem(
name: string,
reference: Range | string,
comment?: string
): NamedItem;
parameters:
- id: name
description: The name of the named item.
type: string
- id: reference
description: The formula or the range that the name will refer to.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
- id: comment
description: Optional. The comment associated with the named item.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.NamedItem:interface" />'
description: ''
- name: 'addNamedItemFormulaLocal(name, formula, comment)'
uid: 'ExcelScript!ExcelScript.Worksheet#addNamedItemFormulaLocal:member(1)'
package: ExcelScript!
fullName: 'addNamedItemFormulaLocal(name, formula, comment)'
summary: Adds a new name to the collection of the given scope using the user's locale for the formula.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addNamedItemFormulaLocal(
name: string,
formula: string,
comment?: string
): NamedItem;
parameters:
- id: name
description: The name of the named item.
type: string
- id: formula
description: The formula in the user's locale that the name will refer to.
type: string
- id: comment
description: Optional. The comment associated with the named item.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.NamedItem:interface" />'
description: ''
- name: addNamedSheetView(name)
uid: 'ExcelScript!ExcelScript.Worksheet#addNamedSheetView:member(1)'
package: ExcelScript!
fullName: addNamedSheetView(name)
summary: Creates a new sheet view with the given name.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addNamedSheetView(name: string): NamedSheetView;'
parameters:
- id: name
description: >-
The name of the sheet view to be created. Throws an error when the provided name already exists, is empty,
or is a name reserved by the worksheet.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.NamedSheetView:interface" />'
description: ''
- name: 'addPivotTable(name, source, destination)'
uid: 'ExcelScript!ExcelScript.Worksheet#addPivotTable:member(1)'
package: ExcelScript!
fullName: 'addPivotTable(name, source, destination)'
summary: Add a PivotTable based on the specified source data and insert it at the top-left cell of the destination range.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addPivotTable(
name: string,
source: Range | string | Table,
destination: Range | string
): PivotTable;
parameters:
- id: name
description: The name of the new PivotTable.
type: string
- id: source
description: >-
The source data for the new PivotTable, this can either be a range (or string address including the
worksheet name) or a table.
type: >-
<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string | <xref
uid="ExcelScript!ExcelScript.Table:interface" />
- id: destination
description: >-
The cell in the upper-left corner of the PivotTable report's destination range (the range on the worksheet
where the resulting report will be placed).
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
return:
type: '<xref uid="ExcelScript!ExcelScript.PivotTable:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script creates a PivotTable from an existing table and adds it to a new worksheet.
* This script assumes there is a table in the current worksheet with columns named "Type" and "Sales".
*/
function main(workbook: ExcelScript.Workbook) {
// Create a PivotTable based on a table in the current worksheet.
let sheet = workbook.getActiveWorksheet();
let table = sheet.getTables()[0];
// Add the PivotTable to a new worksheet.
let newSheet = workbook.addWorksheet("Pivot");
let pivotTable = newSheet.addPivotTable("My Pivot", table, "A1");
// Add fields to the PivotTable to show "Sales" per "Type".
pivotTable.addRowHierarchy(pivotTable.getHierarchy("Type"));
pivotTable.addDataHierarchy(pivotTable.getHierarchy("Sales"));
// Switch to the new worksheet.
newSheet.activate();
}
```
- name: 'addSlicer(slicerSource, sourceField, slicerDestination)'
uid: 'ExcelScript!ExcelScript.Worksheet#addSlicer:member(1)'
package: ExcelScript!
fullName: 'addSlicer(slicerSource, sourceField, slicerDestination)'
summary: Adds a new slicer to the workbook.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addSlicer(
slicerSource: string | PivotTable | Table,
sourceField: string | PivotField | number | TableColumn,
slicerDestination?: string | Worksheet
): Slicer;
parameters:
- id: slicerSource
description: >-
The data source that the new slicer will be based on. It can be a `PivotTable` object, a `Table` object, or
a string. When a PivotTable object is passed, the data source is the source of the `PivotTable` object. When
a `Table` object is passed, the data source is the `Table` object. When a string is passed, it is
interpreted as the name or ID of a PivotTable or table.
type: >-
string | <xref uid="ExcelScript!ExcelScript.PivotTable:interface" /> | <xref
uid="ExcelScript!ExcelScript.Table:interface" />
- id: sourceField
description: >-
The field in the data source to filter by. It can be a `PivotField` object, a `TableColumn` object, the ID
of a `PivotField` or the name or ID of a `TableColumn`<!-- -->.
type: >-
string | <xref uid="ExcelScript!ExcelScript.PivotField:interface" /> | number | <xref
uid="ExcelScript!ExcelScript.TableColumn:interface" />
- id: slicerDestination
description: >-
Optional. The worksheet in which the new slicer will be created. It can be a `Worksheet` object or the name
or ID of a worksheet. This parameter can be omitted if the slicer collection is retrieved from a worksheet.
type: 'string | <xref uid="ExcelScript!ExcelScript.Worksheet:interface" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Slicer:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script adds a slicer for an existing PivotTable on the current worksheet.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the first PivotTable from the current worksheet.
const currentSheet = workbook.getActiveWorksheet();
const pivot = currentSheet.getPivotTables()[0];
// Create the slicer.
// Note that this assumes "Type" is already added as a hierarchy to the PivotTable.
const slicer = currentSheet.addSlicer(
pivot, /* The table or PivotTale to be sliced. */
pivot.getHierarchy("Type").getFields()[0] /* What source field to use as the slicer options. */
);
// Select the items to display.
slicer.selectItems(["Lemon", "Lime"]);
// Set the left margin of the slicer.
slicer.setLeft(400);
}
```
- name: 'addTable(address, hasHeaders)'
uid: 'ExcelScript!ExcelScript.Worksheet#addTable:member(1)'
package: ExcelScript!
fullName: 'addTable(address, hasHeaders)'
summary: >-
Creates a new table. The range object or source address determines the worksheet under which the table will be
added. If the table cannot be added (e.g., because the address is invalid, or the table would overlap with another
table), an error will be thrown.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addTable(address: Range | string, hasHeaders: boolean): Table;'
parameters:
- id: address
description: >-
A `Range` object, or a string address or name of the range representing the data source. If the address does
not contain a sheet name, the currently-active sheet is used.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
- id: hasHeaders
description: >-
A boolean value that indicates whether the data being imported has column labels. If the source does not
contain headers (i.e., when this property set to `false`<!-- -->), Excel will automatically generate a
header and shift the data down by one row.
type: boolean
return:
type: '<xref uid="ExcelScript!ExcelScript.Table:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This sample creates a table from the current worksheet's used range, then sorts it based on the first column.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the current worksheet.
let selectedSheet = workbook.getActiveWorksheet();
// Create a table with the used cells.
let usedRange = selectedSheet.getUsedRange();
let newTable = selectedSheet.addTable(usedRange, true);
// Sort the table using the first column.
newTable.getSort().apply([{ key: 0, ascending: true }]);
}
```
- name: addTextBox(text)
uid: 'ExcelScript!ExcelScript.Worksheet#addTextBox:member(1)'
package: ExcelScript!
fullName: addTextBox(text)
summary: >-
Adds a text box to the worksheet with the provided text as the content. Returns a `Shape` object that represents
the new text box.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addTextBox(text?: string): Shape;'
parameters:
- id: text
description: Represents the text that will be shown in the created text box.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.Shape:interface" />'
description: ''
- name: addVerticalPageBreak(pageBreakRange)
uid: 'ExcelScript!ExcelScript.Worksheet#addVerticalPageBreak:member(1)'
package: ExcelScript!
fullName: addVerticalPageBreak(pageBreakRange)
summary: Adds a page break before the top-left cell of the range specified.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'addVerticalPageBreak(pageBreakRange: Range | string): PageBreak;'
parameters:
- id: pageBreakRange
description: The range immediately after the page break to be added.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
return:
type: '<xref uid="ExcelScript!ExcelScript.PageBreak:interface" />'
description: ''
- name: 'addWorksheetCustomProperty(key, value)'
uid: 'ExcelScript!ExcelScript.Worksheet#addWorksheetCustomProperty:member(1)'
package: ExcelScript!
fullName: 'addWorksheetCustomProperty(key, value)'
summary: >-
Adds a new custom property that maps to the provided key. This overwrites existing custom properties with that
key.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
addWorksheetCustomProperty(
key: string,
value: string
): WorksheetCustomProperty;
parameters:
- id: key
description: >-
The key that identifies the custom property object. It is case-insensitive.The key is limited to 255
characters (larger values will cause an `InvalidArgument` error to be thrown.)
type: string
- id: value
description: The value of this custom property.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.WorksheetCustomProperty:interface" />'
description: ''
- name: calculate(markAllDirty)
uid: 'ExcelScript!ExcelScript.Worksheet#calculate:member(1)'
package: ExcelScript!
fullName: calculate(markAllDirty)
summary: Calculates all cells on a worksheet.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'calculate(markAllDirty: boolean): void;'
parameters:
- id: markAllDirty
description: 'True, to mark all as dirty.'
type: boolean
return:
type: void
description: ''
- name: 'copy(positionType, relativeTo)'
uid: 'ExcelScript!ExcelScript.Worksheet#copy:member(1)'
package: ExcelScript!
fullName: 'copy(positionType, relativeTo)'
summary: Copies a worksheet and places it at the specified position.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: |-
copy(
positionType?: WorksheetPositionType,
relativeTo?: Worksheet
): Worksheet;
parameters:
- id: positionType
description: >-
The location in the workbook to place the newly created worksheet. The default value is "None", which
inserts the worksheet at the beginning of the worksheet.
type: '<xref uid="ExcelScript!ExcelScript.WorksheetPositionType:enum" />'
- id: relativeTo
description: >-
The existing worksheet which determines the newly created worksheet's position. This is only needed if
`positionType` is "Before" or "After".
type: '<xref uid="ExcelScript!ExcelScript.Worksheet:interface" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.Worksheet:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script duplicates a worksheet named "Template".
* The new worksheet is added after the template.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the worksheet named "Template".
let template = workbook.getWorksheet("Template");
// Copy the worksheet.
let newSheet = template.copy(
ExcelScript.WorksheetPositionType.after,
template
);
// Name the worksheet using the current date.
let date = new Date(Date.now());
newSheet.setName(`${date.toDateString()}`);
}
```
- name: delete()
uid: 'ExcelScript!ExcelScript.Worksheet#delete:member(1)'
package: ExcelScript!
fullName: delete()
summary: >-
Deletes the worksheet from the workbook. Note that if the worksheet's visibility is set to "VeryHidden", the
delete operation will fail with an `InvalidOperation` exception. You should first change its visibility to hidden
or visible before deleting it.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'delete(): void;'
return:
type: void
description: |-
#### Examples
```TypeScript
/**
* The following scripts removes the first worksheet in the workbook.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the first worksheet.
let sheet = workbook.getWorksheets()[0];
// Remove that worksheet from the workbook.
sheet.delete();
}
```
- name: enterTemporaryNamedSheetView()
uid: 'ExcelScript!ExcelScript.Worksheet#enterTemporaryNamedSheetView:member(1)'
package: ExcelScript!
fullName: enterTemporaryNamedSheetView()
summary: >-
Creates and activates a new temporary sheet view. Temporary views are removed when closing the application,
exiting the temporary view with the exit method, or switching to another sheet view. The temporary sheet view can
also be accessed with the empty string (""), if the temporary view exists.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'enterTemporaryNamedSheetView(): NamedSheetView;'
return:
type: '<xref uid="ExcelScript!ExcelScript.NamedSheetView:interface" />'
description: ''
- name: exitActiveNamedSheetView()
uid: 'ExcelScript!ExcelScript.Worksheet#exitActiveNamedSheetView:member(1)'
package: ExcelScript!
fullName: exitActiveNamedSheetView()
summary: Exits the currently active sheet view.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'exitActiveNamedSheetView(): void;'
return:
type: void
description: ''
- name: 'findAll(text, criteria)'
uid: 'ExcelScript!ExcelScript.Worksheet#findAll:member(1)'
package: ExcelScript!
fullName: 'findAll(text, criteria)'
summary: >-
Finds all occurrences of the given string based on the criteria specified and returns them as a `RangeAreas`
object, comprising one or more rectangular ranges.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'findAll(text: string, criteria: WorksheetSearchCriteria): RangeAreas;'
parameters:
- id: text
description: The string to find.
type: string
- id: criteria
description: >-
Additional search criteria, including whether the search needs to match the entire cell or be
case-sensitive.
type: '<xref uid="ExcelScript!ExcelScript.WorksheetSearchCriteria:interface" />'
return:
type: '<xref uid="ExcelScript!ExcelScript.RangeAreas:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script searches through a worksheet and finds cells containing "No".
* Those cells are filled red.
* Use Range.find instead of Worksheet.findAll when you want to limit the search to a specific range.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the current, active worksheet.
let worksheet = workbook.getActiveWorksheet();
let noCells = worksheet.findAll("No", { completeMatch: true });
// Set the fill color to red.
noCells.getFormat().getFill().setColor("red");
}
```
- name: getActiveNamedSheetView()
uid: 'ExcelScript!ExcelScript.Worksheet#getActiveNamedSheetView:member(1)'
package: ExcelScript!
fullName: getActiveNamedSheetView()
summary: Gets the worksheet's currently active sheet view.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getActiveNamedSheetView(): NamedSheetView;'
return:
type: '<xref uid="ExcelScript!ExcelScript.NamedSheetView:interface" />'
description: ''
- name: getAutoFilter()
uid: 'ExcelScript!ExcelScript.Worksheet#getAutoFilter:member(1)'
package: ExcelScript!
fullName: getAutoFilter()
summary: Represents the `AutoFilter` object of the worksheet.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getAutoFilter(): AutoFilter;'
return:
type: '<xref uid="ExcelScript!ExcelScript.AutoFilter:interface" />'
description: |-
#### Examples
```TypeScript
/**
* This script creates an autoFilter on the worksheet that filters out rows based on column values.
* The autoFilter filters to only include rows that have a value in column D in the top 10 percentile
* (of column D values).
*/
function main(workbook: ExcelScript.Workbook) {
const currentSheet = workbook.getActiveWorksheet();
const dataRange = currentSheet.getUsedRange();
// Add a filter that will only show the rows with the top 10% of values in column D
// (index 3, assuming the used range spans from at least A:D).
currentSheet.getAutoFilter().apply(dataRange, 3, {
criterion1: "10",
filterOn: ExcelScript.FilterOn.topPercent
});
}
```
- name: 'getCell(row, column)'
uid: 'ExcelScript!ExcelScript.Worksheet#getCell:member(1)'
package: ExcelScript!
fullName: 'getCell(row, column)'
summary: >-
Gets the `Range` object containing the single cell based on row and column numbers. The cell can be outside the
bounds of its parent range, so long as it stays within the worksheet grid.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getCell(row: number, column: number): Range;'
parameters:
- id: row
description: The row number of the cell to be retrieved. Zero-indexed.
type: number
- id: column
description: The column number of the cell to be retrieved. Zero-indexed.
type: number
return:
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" />'
description: ''
- name: getChart(name)
uid: 'ExcelScript!ExcelScript.Worksheet#getChart:member(1)'
package: ExcelScript!
fullName: getChart(name)
summary: >-
Gets a chart using its name. If there are multiple charts with the same name, the first one will be returned. If
the chart doesn't exist, then this method returns `undefined`<!-- -->.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getChart(name: string): Chart | undefined;'
parameters:
- id: name
description: Name of the chart to be retrieved.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.Chart:interface" /> | undefined'
description: |-
#### Examples
```TypeScript
/**
* This sample moves an existing chart to a specific place on the worksheet.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the current worksheet.
let selectedSheet = workbook.getActiveWorksheet();
// Get an existing chart named "ColumnChart".
let chart = selectedSheet.getChart("ColumnChart");
// Place the chart over the range "F1:L13".
chart.setPosition("F1", "L13");
}
```
- name: getCharts()
uid: 'ExcelScript!ExcelScript.Worksheet#getCharts:member(1)'
package: ExcelScript!
fullName: getCharts()
summary: Returns a collection of charts that are part of the worksheet.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getCharts(): Chart[];'
return:
type: '<xref uid="ExcelScript!ExcelScript.Chart:interface" />[]'
description: ''
- name: getComment(commentId)
uid: 'ExcelScript!ExcelScript.Worksheet#getComment:member(1)'
package: ExcelScript!
fullName: getComment(commentId)
summary: >-
Gets a comment from the collection based on its ID. If the comment object does not exist, then this method returns
`undefined`<!-- -->.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getComment(commentId: string): Comment | undefined;'
parameters:
- id: commentId
description: The identifier for the comment.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.Comment:interface" /> | undefined'
description: ''
- name: getCommentByCell(cellAddress)
uid: 'ExcelScript!ExcelScript.Worksheet#getCommentByCell:member(1)'
package: ExcelScript!
fullName: getCommentByCell(cellAddress)
summary: 'Gets the comment from the specified cell. If there is no comment in the cell, an error is thrown.'
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getCommentByCell(cellAddress: Range | string): Comment;'
parameters:
- id: cellAddress
description: >-
The cell which the comment is on. This can be a `Range` object or a string. If it's a string, it must
contain the full address, including the sheet name. An `InvalidArgument` error is thrown if the provided
range is larger than one cell.
type: '<xref uid="ExcelScript!ExcelScript.Range:interface" /> | string'
return:
type: '<xref uid="ExcelScript!ExcelScript.Comment:interface" />'
description: ''
- name: getCommentByReplyId(replyId)
uid: 'ExcelScript!ExcelScript.Worksheet#getCommentByReplyId:member(1)'
package: ExcelScript!
fullName: getCommentByReplyId(replyId)
summary: Gets the comment to which the given reply is connected.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getCommentByReplyId(replyId: string): Comment;'
parameters:
- id: replyId
description: The identifier of comment reply.
type: string
return:
type: '<xref uid="ExcelScript!ExcelScript.Comment:interface" />'
description: ''
- name: getComments()
uid: 'ExcelScript!ExcelScript.Worksheet#getComments:member(1)'
package: ExcelScript!
fullName: getComments()
summary: Returns a collection of all the Comments objects on the worksheet.
remarks: ''
isPreview: false
isDeprecated: false
syntax:
content: 'getComments(): Comment[];'
return:
type: '<xref uid="ExcelScript!ExcelScript.Comment:interface" />[]'
description: ''
- name: getCustomProperties()
uid: 'ExcelScript!ExcelScript.Worksheet#getCustomProperties:member(1)'
package: ExcelScript!
fullName: getCustomProperties()