Skip to content

Commit 8b68baa

Browse files
[excel] (Query, Range, Worksheet, Shape) Add samples to highly viewed pages (#330)
* Add query sample * Adding samples to highly viewed pages * Fix typos * Apply suggestions from code review Co-authored-by: Alison McKay <[email protected]> --------- Co-authored-by: Alison McKay <[email protected]>
1 parent e561983 commit 8b68baa

File tree

7 files changed

+202
-10
lines changed

7 files changed

+202
-10
lines changed

docs/docs-ref-autogen/excel/excelscript/excelscript.query.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@ uid: 'ExcelScript!ExcelScript.Query:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.Query
66
summary: Represents a Power Query query.
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This script logs information about all the Power Query queries in the workbook.
15+
*/
16+
function main(workbook: ExcelScript.Workbook) {
17+
// Get all the Power Query queries in the workbook.
18+
const queries = workbook.getQueries();
19+
20+
// For each query, log the date it was last refreshed.
21+
queries.forEach((query: ExcelScript.Query) => {
22+
console.log(`Query ${query.getName()} - last refreshed ${query.getRefreshDate()}`);
23+
});
24+
}
25+
```
826
isPreview: false
927
isDeprecated: false
1028
type: interface

docs/docs-ref-autogen/excel/excelscript/excelscript.range.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,27 @@ methods:
23422342
content: 'select(): void;'
23432343
return:
23442344
type: void
2345-
description: ''
2345+
description: |-
2346+
2347+
2348+
#### Examples
2349+
2350+
```TypeScript
2351+
/**
2352+
* This script selects the first row of a table.
2353+
*/
2354+
function main(workbook: ExcelScript.Workbook) {
2355+
// Get the first table on the current worksheet.
2356+
const sheet = workbook.getActiveWorksheet()
2357+
const table = sheet.getTables()[0];
2358+
2359+
// Get the first data row in the table.
2360+
const row = table.getRangeBetweenHeaderAndTotal().getRow(0);
2361+
2362+
// Select the first data row.
2363+
row.select();
2364+
}
2365+
```
23462366
- name: setColumnHidden(columnHidden)
23472367
uid: 'ExcelScript!ExcelScript.Range#setColumnHidden:member(1)'
23482368
package: ExcelScript!

docs/docs-ref-autogen/excel/excelscript/excelscript.shapefont.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,28 @@ uid: 'ExcelScript!ExcelScript.ShapeFont:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.ShapeFont
66
summary: 'Represents the font attributes, such as font name, font size, and color, for a shape''s `TextRange` object.'
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This sample sets the font of a shape to be bold.
15+
*/
16+
function main(workbook: ExcelScript.Workbook) {
17+
// Get the first shape in the current worksheet.
18+
const sheet = workbook.getActiveWorksheet();
19+
const shape = sheet.getShapes()[0];
20+
21+
// Get the text font from the shape.
22+
const text: ExcelScript.TextRange = shape.getTextFrame().getTextRange();
23+
const shapeTextFont: ExcelScript.ShapeFont = text.getFont();
24+
25+
// Set the font to be bold.
26+
shapeTextFont.setBold(true);
27+
}
28+
```
829
isPreview: false
930
isDeprecated: false
1031
type: interface

docs/docs-ref-autogen/excel/excelscript/excelscript.textrange.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,28 @@ methods:
3939
content: 'getFont(): ShapeFont;'
4040
return:
4141
type: '<xref uid="ExcelScript!ExcelScript.ShapeFont:interface" />'
42-
description: ''
42+
description: |-
43+
44+
45+
#### Examples
46+
47+
```TypeScript
48+
/**
49+
* This sample sets the font of a shape to be bold.
50+
*/
51+
function main(workbook: ExcelScript.Workbook) {
52+
// Get the first shape in the current worksheet.
53+
const sheet = workbook.getActiveWorksheet();
54+
const shape = sheet.getShapes()[0];
55+
56+
// Get the text font from the shape.
57+
const text: ExcelScript.TextRange = shape.getTextFrame().getTextRange();
58+
const shapeTextFont: ExcelScript.ShapeFont = text.getFont();
59+
60+
// Set the font to be bold.
61+
shapeTextFont.setBold(true);
62+
}
63+
```
4364
- name: 'getSubstring(start, length)'
4465
uid: 'ExcelScript!ExcelScript.TextRange#getSubstring:member(1)'
4566
package: ExcelScript!

docs/docs-ref-autogen/excel/excelscript/excelscript.worksheetprotection.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,33 @@ uid: 'ExcelScript!ExcelScript.WorksheetProtection:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.WorksheetProtection
66
summary: Represents the protection of a worksheet object.
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This script pauses the protection of a worksheet by using the provided password.
15+
* This password could come from a Power Automate flow.
16+
*/
17+
function main(workbook: ExcelScript.Workbook, password: string) {
18+
// Get the worksheet named "Sales".
19+
const sheet = workbook.getWorksheet("Sales");
20+
const protection: ExcelScript.WorksheetProtection = sheet.getProtection();
21+
22+
// Check if the provided password works.
23+
if (protection.checkPassword(password)) {
24+
protection.pauseProtection(password);
25+
26+
// Edit the worksheet...
27+
28+
protection.resumeProtection();
29+
} else {
30+
console.log("Incorrect password");
31+
}
32+
}
33+
```
834
isPreview: false
935
isDeprecated: false
1036
type: interface

docs/sample-scripts/excel-scripts.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,20 @@
35773577
// Apply the given protection options.
35783578
sheetProtection.protect(protectionOptions);
35793579
}
3580+
'ExcelScript.Query:interface':
3581+
- |-
3582+
/**
3583+
* This script logs information about all the Power Query queries in the workbook.
3584+
*/
3585+
function main(workbook: ExcelScript.Workbook) {
3586+
// Get all the Power Query queries in the workbook.
3587+
const queries = workbook.getQueries();
3588+
3589+
// For each query, log the date it was last refreshed.
3590+
queries.forEach((query: ExcelScript.Query) => {
3591+
console.log(`Query ${query.getName()} - last refreshed ${query.getRefreshDate()}`);
3592+
});
3593+
}
35803594
'ExcelScript.Range:interface':
35813595
- |-
35823596
/**
@@ -4205,6 +4219,22 @@
42054219
// Change the value of any cells with the value "monthly special".
42064220
range.replaceAll("monthly special", "parsnip", {completeMatch: true});
42074221
}
4222+
'ExcelScript.Range#select:member(1)':
4223+
- |-
4224+
/**
4225+
* This script selects the first row of a table.
4226+
*/
4227+
function main(workbook: ExcelScript.Workbook) {
4228+
// Get the first table on the current worksheet.
4229+
const sheet = workbook.getActiveWorksheet()
4230+
const table = sheet.getTables()[0];
4231+
4232+
// Get the first data row in the table.
4233+
const row = table.getRangeBetweenHeaderAndTotal().getRow(0);
4234+
4235+
// Select the first data row.
4236+
row.select();
4237+
}
42084238
'ExcelScript.Range#setFormula:member(1)':
42094239
- |-
42104240
/*
@@ -5215,6 +5245,23 @@
52155245
textFrame.getTextRange().setText(value.toString());
52165246
textFrame.setAutoSizeSetting(ExcelScript.ShapeAutoSize.autoSizeShapeToFitText);
52175247
}
5248+
'ExcelScript.ShapeFont:interface':
5249+
- |-
5250+
/**
5251+
* This sample sets the font of a shape to be bold.
5252+
*/
5253+
function main(workbook: ExcelScript.Workbook) {
5254+
// Get the first shape in the current worksheet.
5255+
const sheet = workbook.getActiveWorksheet();
5256+
const shape = sheet.getShapes()[0];
5257+
5258+
// Get the text font from the shape.
5259+
const text: ExcelScript.TextRange = shape.getTextFrame().getTextRange();
5260+
const shapeTextFont: ExcelScript.ShapeFont = text.getFont();
5261+
5262+
// Set the font to be bold.
5263+
shapeTextFont.setBold(true);
5264+
}
52185265
'ExcelScript.SheetVisibility:enum':
52195266
- |-
52205267
/**
@@ -5805,6 +5852,23 @@
58055852
const hexText: ExcelScript.TextRange = hexagon.getTextFrame().getTextRange();
58065853
hexText.setText("Forest");
58075854
}
5855+
'ExcelScript.TextRange#getFont:member(1)':
5856+
- |-
5857+
/**
5858+
* This sample sets the font of a shape to be bold.
5859+
*/
5860+
function main(workbook: ExcelScript.Workbook) {
5861+
// Get the first shape in the current worksheet.
5862+
const sheet = workbook.getActiveWorksheet();
5863+
const shape = sheet.getShapes()[0];
5864+
5865+
// Get the text font from the shape.
5866+
const text: ExcelScript.TextRange = shape.getTextFrame().getTextRange();
5867+
const shapeTextFont: ExcelScript.ShapeFont = text.getFont();
5868+
5869+
// Set the font to be bold.
5870+
shapeTextFont.setBold(true);
5871+
}
58085872
'ExcelScript.TextRange#getText:member(1)':
58095873
- |-
58105874
/**
@@ -6482,6 +6546,28 @@
64826546
let date = new Date(Date.now());
64836547
newSheet.setName(`${date.toDateString()}`);
64846548
}
6549+
'ExcelScript.WorksheetProtection:interface':
6550+
- |-
6551+
/**
6552+
* This script pauses the protection of a worksheet by using the provided password.
6553+
* This password could come from a Power Automate flow.
6554+
*/
6555+
function main(workbook: ExcelScript.Workbook, password: string) {
6556+
// Get the worksheet named "Sales".
6557+
const sheet = workbook.getWorksheet("Sales");
6558+
const protection: ExcelScript.WorksheetProtection = sheet.getProtection();
6559+
6560+
// Check if the provided password works.
6561+
if (protection.checkPassword(password)) {
6562+
protection.pauseProtection(password);
6563+
6564+
// Edit the worksheet...
6565+
6566+
protection.resumeProtection();
6567+
} else {
6568+
console.log("Incorrect password");
6569+
}
6570+
}
64856571
'ExcelScript.WorksheetProtection#protect:member(1)':
64866572
- |-
64876573
/**

generate-docs/API Coverage Report.csv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ ExcelScript.ProtectionSelectionMode,N/A,Enum,Missing,true
23472347
ExcelScript.ProtectionSelectionMode,"none",EnumField,Fine,false
23482348
ExcelScript.ProtectionSelectionMode,"normal",EnumField,Fine,false
23492349
ExcelScript.ProtectionSelectionMode,"unlocked",EnumField,Fine,false
2350-
ExcelScript.Query,N/A,Class,Poor,false
2350+
ExcelScript.Query,N/A,Class,Poor,true
23512351
ExcelScript.Query,"getError()",Method,Poor,false
23522352
ExcelScript.Query,"getLoadedTo()",Method,Poor,false
23532353
ExcelScript.Query,"getLoadedToDataModel()",Method,Poor,false
@@ -2455,7 +2455,7 @@ ExcelScript.Range,"merge(across)",Method,Fine,true
24552455
ExcelScript.Range,"moveTo(destinationRange)",Method,Poor,false
24562456
ExcelScript.Range,"removeDuplicates(columns, includesHeader)",Method,Poor,false
24572457
ExcelScript.Range,"replaceAll(text, replacement, criteria)",Method,Poor,true
2458-
ExcelScript.Range,"select()",Method,Poor,false
2458+
ExcelScript.Range,"select()",Method,Poor,true
24592459
ExcelScript.Range,"setColumnHidden(columnHidden)",Method,Poor,false
24602460
ExcelScript.Range,"setDirty()",Method,Poor,false
24612461
ExcelScript.Range,"setFormula(formula)",Method,Poor,true
@@ -2725,7 +2725,7 @@ ExcelScript.ShapeFillType,"noFill",EnumField,Poor,false
27252725
ExcelScript.ShapeFillType,"pattern",EnumField,Poor,false
27262726
ExcelScript.ShapeFillType,"pictureAndTexture",EnumField,Poor,false
27272727
ExcelScript.ShapeFillType,"solid",EnumField,Poor,false
2728-
ExcelScript.ShapeFont,N/A,Class,Fine,false
2728+
ExcelScript.ShapeFont,N/A,Class,Fine,true
27292729
ExcelScript.ShapeFont,"getBold()",Method,Poor,false
27302730
ExcelScript.ShapeFont,"getColor()",Method,Poor,false
27312731
ExcelScript.ShapeFont,"getItalic()",Method,Poor,false
@@ -3075,7 +3075,7 @@ ExcelScript.TextFrame,"setTopMargin(topMargin)",Method,Poor,false
30753075
ExcelScript.TextFrame,"setVerticalAlignment(verticalAlignment)",Method,Poor,false
30763076
ExcelScript.TextFrame,"setVerticalOverflow(verticalOverflow)",Method,Poor,false
30773077
ExcelScript.TextRange,N/A,Class,Fine,true
3078-
ExcelScript.TextRange,"getFont()",Method,Poor,false
3078+
ExcelScript.TextRange,"getFont()",Method,Fine,true
30793079
ExcelScript.TextRange,"getSubstring(start, length)",Method,Poor,false
30803080
ExcelScript.TextRange,"getText()",Method,Poor,true
30813081
ExcelScript.TextRange,"setText(text)",Method,Poor,false
@@ -3307,7 +3307,7 @@ ExcelScript.WorksheetPositionType,"before",EnumField,Missing,false
33073307
ExcelScript.WorksheetPositionType,"beginning",EnumField,Missing,false
33083308
ExcelScript.WorksheetPositionType,"end",EnumField,Missing,false
33093309
ExcelScript.WorksheetPositionType,"none",EnumField,Missing,false
3310-
ExcelScript.WorksheetProtection,N/A,Class,Fine,false
3310+
ExcelScript.WorksheetProtection,N/A,Class,Fine,true
33113311
ExcelScript.WorksheetProtection,"addAllowEditRange(title, rangeAddress, options)",Method,Poor,false
33123312
ExcelScript.WorksheetProtection,"checkPassword(password)",Method,Poor,false
33133313
ExcelScript.WorksheetProtection,"getAllowEditRange(key)",Method,Poor,false

0 commit comments

Comments
 (0)