Skip to content

Commit d4bf51b

Browse files
authored
[excel] (Worksheet) Adding edit range and page zoom samples (#349)
* Adding edit range and page zoom samples * Fix grammar
1 parent dddc0e0 commit d4bf51b

File tree

6 files changed

+176
-8
lines changed

6 files changed

+176
-8
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,33 @@ uid: 'ExcelScript!ExcelScript.AllowEditRangeOptions:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.AllowEditRangeOptions
66
summary: The interface used to construct optional fields of the `AllowEditRange` object.
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This script adds a password-protected, editable range
15+
* to an otherwise protected worksheet.
16+
*/
17+
function main(workbook: ExcelScript.Workbook, password: string) {
18+
// Get the protection object for the "Data" worksheet.
19+
const dataSheet = workbook.getWorksheet("Data");
20+
const sheetProtection = dataSheet.getProtection();
21+
22+
// Set the password needed to edit the range to be the user provided string.
23+
const editRangeProperties : ExcelScript.AllowEditRangeOptions = {
24+
password: password
25+
};
26+
27+
// Set range "D2:D6" to be editable if the password is provided.
28+
sheetProtection.addAllowEditRange("Notes Section", "D2:D6", editRangeProperties);
29+
30+
// Protect the worksheet.
31+
sheetProtection.protect();
32+
}
33+
```
834
isPreview: false
935
isDeprecated: false
1036
type: interface

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,24 @@ methods:
841841
type: '<xref uid="ExcelScript!ExcelScript.PageLayoutZoomOptions:interface" />'
842842
return:
843843
type: void
844-
description: ''
844+
description: |-
845+
846+
847+
#### Examples
848+
849+
```TypeScript
850+
/**
851+
* This script changes the scale-to-fit of the page layout.
852+
*/
853+
function main(workbook: ExcelScript.Workbook) {
854+
// Get the current worksheet.
855+
const sheet = workbook.getActiveWorksheet();
856+
857+
// Scale the layout to half size for printing.
858+
const layout = sheet.getPageLayout();
859+
const zoomOptions: ExcelScript.PageLayoutZoomOptions = {
860+
scale: 50
861+
}
862+
layout.setZoom(zoomOptions)
863+
}
864+
```

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@ uid: 'ExcelScript!ExcelScript.PageLayoutZoomOptions:interface'
44
package: ExcelScript!
55
fullName: ExcelScript.PageLayoutZoomOptions
66
summary: Represents page zoom properties.
7-
remarks: ''
7+
remarks: |-
8+
9+
10+
#### Examples
11+
12+
```TypeScript
13+
/**
14+
* This script changes the scale-to-fit of the page layout.
15+
*/
16+
function main(workbook: ExcelScript.Workbook) {
17+
// Get the current worksheet.
18+
const sheet = workbook.getActiveWorksheet();
19+
20+
// Scale the layout to half size for printing.
21+
const layout = sheet.getPageLayout();
22+
const zoomOptions: ExcelScript.PageLayoutZoomOptions = {
23+
scale: 50
24+
}
25+
layout.setZoom(zoomOptions)
26+
}
27+
```
828
isPreview: false
929
isDeprecated: false
1030
type: interface

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,33 @@ methods:
6565
type: '<xref uid="ExcelScript!ExcelScript.AllowEditRangeOptions:interface" />'
6666
return:
6767
type: void
68-
description: ''
68+
description: |-
69+
70+
71+
#### Examples
72+
73+
```TypeScript
74+
/**
75+
* This script adds a password-protected, editable range
76+
* to an otherwise protected worksheet.
77+
*/
78+
function main(workbook: ExcelScript.Workbook, password: string) {
79+
// Get the protection object for the "Data" worksheet.
80+
const dataSheet = workbook.getWorksheet("Data");
81+
const sheetProtection = dataSheet.getProtection();
82+
83+
// Set the password needed to edit the range to be the user provided string.
84+
const editRangeProperties : ExcelScript.AllowEditRangeOptions = {
85+
password: password
86+
};
87+
88+
// Set range "D2:D6" to be editable if the password is provided.
89+
sheetProtection.addAllowEditRange("Notes Section", "D2:D6", editRangeProperties);
90+
91+
// Protect the worksheet.
92+
sheetProtection.protect();
93+
}
94+
```
6995
- name: checkPassword(password)
7096
uid: 'ExcelScript!ExcelScript.WorksheetProtection#checkPassword:member(1)'
7197
package: ExcelScript!

docs/sample-scripts/excel-scripts.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@
1111
const dataHierarchy = pivotTable.getDataHierarchies()[0];
1212
dataHierarchy.setSummarizeBy(ExcelScript.AggregationFunction.average);
1313
}
14+
'ExcelScript.AllowEditRangeOptions:interface':
15+
- |-
16+
/**
17+
* This script adds a password-protected, editable range
18+
* to an otherwise protected worksheet.
19+
*/
20+
function main(workbook: ExcelScript.Workbook, password: string) {
21+
// Get the protection object for the "Data" worksheet.
22+
const dataSheet = workbook.getWorksheet("Data");
23+
const sheetProtection = dataSheet.getProtection();
24+
25+
// Set the password needed to edit the range to be the user provided string.
26+
const editRangeProperties : ExcelScript.AllowEditRangeOptions = {
27+
password: password
28+
};
29+
30+
// Set range "D2:D6" to be editable if the password is provided.
31+
sheetProtection.addAllowEditRange("Notes Section", "D2:D6", editRangeProperties);
32+
33+
// Protect the worksheet.
34+
sheetProtection.protect();
35+
}
1436
'ExcelScript.Application#calculate:member(1)':
1537
- |-
1638
/**
@@ -2969,6 +2991,38 @@
29692991
layout.setPrintOrder(ExcelScript.PrintOrder.overThenDown);
29702992
});
29712993
}
2994+
'ExcelScript.PageLayout#setZoom:member(1)':
2995+
- |-
2996+
/**
2997+
* This script changes the scale-to-fit of the page layout.
2998+
*/
2999+
function main(workbook: ExcelScript.Workbook) {
3000+
// Get the current worksheet.
3001+
const sheet = workbook.getActiveWorksheet();
3002+
3003+
// Scale the layout to half size for printing.
3004+
const layout = sheet.getPageLayout();
3005+
const zoomOptions: ExcelScript.PageLayoutZoomOptions = {
3006+
scale: 50
3007+
}
3008+
layout.setZoom(zoomOptions)
3009+
}
3010+
'ExcelScript.PageLayoutZoomOptions:interface':
3011+
- |-
3012+
/**
3013+
* This script changes the scale-to-fit of the page layout.
3014+
*/
3015+
function main(workbook: ExcelScript.Workbook) {
3016+
// Get the current worksheet.
3017+
const sheet = workbook.getActiveWorksheet();
3018+
3019+
// Scale the layout to half size for printing.
3020+
const layout = sheet.getPageLayout();
3021+
const zoomOptions: ExcelScript.PageLayoutZoomOptions = {
3022+
scale: 50
3023+
}
3024+
layout.setZoom(zoomOptions)
3025+
}
29723026
'ExcelScript.PageOrientation:enum':
29733027
- |-
29743028
/**
@@ -6908,6 +6962,28 @@
69086962
console.log("Incorrect password");
69096963
}
69106964
}
6965+
'ExcelScript.WorksheetProtection#addAllowEditRange:member(1)':
6966+
- |-
6967+
/**
6968+
* This script adds a password-protected, editable range
6969+
* to an otherwise protected worksheet.
6970+
*/
6971+
function main(workbook: ExcelScript.Workbook, password: string) {
6972+
// Get the protection object for the "Data" worksheet.
6973+
const dataSheet = workbook.getWorksheet("Data");
6974+
const sheetProtection = dataSheet.getProtection();
6975+
6976+
// Set the password needed to edit the range to be the user provided string.
6977+
const editRangeProperties : ExcelScript.AllowEditRangeOptions = {
6978+
password: password
6979+
};
6980+
6981+
// Set range "D2:D6" to be editable if the password is provided.
6982+
sheetProtection.addAllowEditRange("Notes Section", "D2:D6", editRangeProperties);
6983+
6984+
// Protect the worksheet.
6985+
sheetProtection.protect();
6986+
}
69116987
'ExcelScript.WorksheetProtection#protect:member(1)':
69126988
- |-
69136989
/**

generate-docs/API Coverage Report.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ExcelScript.AllowEditRange,"pauseProtection(password)",Method,Poor,false
2222
ExcelScript.AllowEditRange,"setAddress(address)",Method,Poor,false
2323
ExcelScript.AllowEditRange,"setPassword(password)",Method,Poor,false
2424
ExcelScript.AllowEditRange,"setTitle(title)",Method,Poor,false
25-
ExcelScript.AllowEditRangeOptions,N/A,Class,Fine,false
25+
ExcelScript.AllowEditRangeOptions,N/A,Class,Fine,true
2626
ExcelScript.AllowEditRangeOptions,"password",Property,Fine,false
2727
ExcelScript.Application,N/A,Class,Fine,false
2828
ExcelScript.Application,"calculate(calculationType)",Method,Fine,true
@@ -2065,15 +2065,15 @@ ExcelScript.PageLayout,"setPrintTitleColumns(printTitleColumns)",Method,Poor,fal
20652065
ExcelScript.PageLayout,"setPrintTitleRows(printTitleRows)",Method,Poor,false
20662066
ExcelScript.PageLayout,"setRightMargin(rightMargin)",Method,Poor,false
20672067
ExcelScript.PageLayout,"setTopMargin(topMargin)",Method,Poor,false
2068-
ExcelScript.PageLayout,"setZoom(zoom)",Method,Poor,false
2068+
ExcelScript.PageLayout,"setZoom(zoom)",Method,Poor,true
20692069
ExcelScript.PageLayoutMarginOptions,N/A,Class,Fine,false
20702070
ExcelScript.PageLayoutMarginOptions,"bottom",Property,Fine,false
20712071
ExcelScript.PageLayoutMarginOptions,"footer",Property,Fine,false
20722072
ExcelScript.PageLayoutMarginOptions,"header",Property,Fine,false
20732073
ExcelScript.PageLayoutMarginOptions,"left",Property,Fine,false
20742074
ExcelScript.PageLayoutMarginOptions,"right",Property,Fine,false
20752075
ExcelScript.PageLayoutMarginOptions,"top",Property,Fine,false
2076-
ExcelScript.PageLayoutZoomOptions,N/A,Class,Poor,false
2076+
ExcelScript.PageLayoutZoomOptions,N/A,Class,Poor,true
20772077
ExcelScript.PageLayoutZoomOptions,"horizontalFitToPages",Property,Good,false
20782078
ExcelScript.PageLayoutZoomOptions,"scale",Property,Good,false
20792079
ExcelScript.PageLayoutZoomOptions,"verticalFitToPages",Property,Good,false
@@ -3308,7 +3308,7 @@ ExcelScript.WorksheetPositionType,"beginning",EnumField,Missing,false
33083308
ExcelScript.WorksheetPositionType,"end",EnumField,Missing,false
33093309
ExcelScript.WorksheetPositionType,"none",EnumField,Missing,false
33103310
ExcelScript.WorksheetProtection,N/A,Class,Fine,true
3311-
ExcelScript.WorksheetProtection,"addAllowEditRange(title, rangeAddress, options)",Method,Poor,false
3311+
ExcelScript.WorksheetProtection,"addAllowEditRange(title, rangeAddress, options)",Method,Fine,true
33123312
ExcelScript.WorksheetProtection,"checkPassword(password)",Method,Poor,false
33133313
ExcelScript.WorksheetProtection,"getAllowEditRange(key)",Method,Poor,false
33143314
ExcelScript.WorksheetProtection,"getAllowEditRanges()",Method,Poor,false

0 commit comments

Comments
 (0)