Skip to content

Commit 6e50798

Browse files
authored
[Excel] Map existing snippets to ref docs (#1000)
* [Excel] Map existing snippets to ref docs * Map CardLayoutSection to different snippet * Map EntityPropertyType and EntityViewLayouts to shorter snippet * Add explicit types as comments
1 parent 88b7fe2 commit 6e50798

File tree

3 files changed

+350
-4
lines changed

3 files changed

+350
-4
lines changed

samples/excel/20-data-types/data-types-entity-attribution.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ script:
5050
const entity: Excel.EntityCellValue = {
5151
type: Excel.CellValueType.entity,
5252
text: productName,
53-
properties: {
53+
properties: { /* Excel.EntityPropertyType */
5454
"Product ID": {
5555
type: Excel.CellValueType.string,
5656
basicValue: productID.toString() || ""
@@ -70,10 +70,10 @@ script:
7070
numberFormat: "$* #,##0.00"
7171
}
7272
},
73-
layouts: {
74-
card: {
73+
layouts: { /* Excel.EntityViewLayouts */
74+
card: { /* Excel.EntityCardLayout */
7575
title: { property: "Product Name" },
76-
sections: [
76+
sections: [ /* Excel.CardLayoutSection */
7777
{
7878
layout: "List",
7979
properties: ["Product ID"]
411 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,141 @@ Excel.CalculationType:enum:
445445
context.application.calculate(Excel.CalculationType.recalculate);
446446
await context.sync();
447447
});
448+
Excel.CardLayoutSection:type:
449+
- >-
450+
// Link to full sample:
451+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml
452+
453+
454+
function makeProductEntity(productID: number, productName: string, product?:
455+
any) {
456+
const entity: Excel.EntityCellValue = {
457+
type: Excel.CellValueType.entity,
458+
text: productName,
459+
properties: { /* Excel.EntityPropertyType */
460+
"Product ID": {
461+
type: Excel.CellValueType.string,
462+
basicValue: productID.toString() || ""
463+
},
464+
"Product Name": {
465+
type: Excel.CellValueType.string,
466+
basicValue: productName || ""
467+
},
468+
"Quantity Per Unit": {
469+
type: Excel.CellValueType.string,
470+
basicValue: product.quantityPerUnit || ""
471+
},
472+
// Add Unit Price as a formatted number.
473+
"Unit Price": {
474+
type: Excel.CellValueType.formattedNumber,
475+
basicValue: product.unitPrice,
476+
numberFormat: "$* #,##0.00"
477+
}
478+
},
479+
layouts: { /* Excel.EntityViewLayouts */
480+
card: { /* Excel.EntityCardLayout */
481+
title: { property: "Product Name" },
482+
sections: [ /* Excel.CardLayoutSection */
483+
{
484+
layout: "List",
485+
properties: ["Product ID"]
486+
},
487+
{
488+
layout: "List",
489+
title: "Quantity and price",
490+
collapsible: true,
491+
collapsed: false,
492+
properties: ["Quantity Per Unit", "Unit Price"]
493+
}
494+
]
495+
}
496+
},
497+
provider: {
498+
description: product.providerName, // Name of the data provider. Displays as a tooltip when hovering over the logo. Also displays as a fallback if the source address for the image is broken.
499+
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
500+
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
501+
}
502+
};
503+
504+
return entity;
505+
}
506+
Excel.CellBorder:interface:
507+
- >-
508+
// Link to full sample:
509+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml
510+
511+
512+
await Excel.run(async (context) => {
513+
const sheet = context.workbook.worksheets.getActiveWorksheet();
514+
515+
// Creating the SettableCellProperties objects to use for the range.
516+
// In your add-in, these should be created once, outside the function.
517+
const topHeaderProps: Excel.SettableCellProperties = {
518+
// The style property takes a string matching the name of an Excel style.
519+
// Built-in style names are listed in the `BuiltInStyle` enum.
520+
// Note that a style will overwrite any formatting,
521+
// so do not use the format property with the style property.
522+
style: "Heading1"
523+
};
524+
525+
const headerProps: Excel.SettableCellProperties = {
526+
// Any subproperties of format that are not set will not be changed when these cell properties are set.
527+
format: {
528+
fill: {
529+
color: "Blue"
530+
},
531+
font: {
532+
color: "White",
533+
bold: true
534+
}
535+
}
536+
};
537+
538+
const nonApplicableProps: Excel.SettableCellProperties = {
539+
format: {
540+
fill: {
541+
pattern: Excel.FillPattern.gray25
542+
},
543+
font: {
544+
color: "Gray",
545+
italic: true
546+
}
547+
}
548+
};
549+
550+
const matchupScoreProps: Excel.SettableCellProperties = {
551+
format: {
552+
borders: {
553+
bottom: {
554+
style: Excel.BorderLineStyle.continuous
555+
},
556+
left: {
557+
style: Excel.BorderLineStyle.continuous
558+
},
559+
right: {
560+
style: Excel.BorderLineStyle.continuous
561+
},
562+
top: {
563+
style: Excel.BorderLineStyle.continuous
564+
}
565+
}
566+
}
567+
};
568+
569+
const range = sheet.getRange("A1:E5");
570+
571+
// You can use empty JSON objects to avoid changing a cell's properties.
572+
range.setCellProperties([
573+
[topHeaderProps, {}, {}, {}, {}],
574+
[{}, {}, headerProps, headerProps, headerProps],
575+
[{}, headerProps, nonApplicableProps, matchupScoreProps, matchupScoreProps],
576+
[{}, headerProps, matchupScoreProps, nonApplicableProps, matchupScoreProps],
577+
[{}, headerProps, matchupScoreProps, matchupScoreProps, nonApplicableProps]
578+
]);
579+
580+
sheet.getUsedRange().format.autofitColumns();
581+
await context.sync();
582+
});
448583
Excel.CellControl:type:
449584
- >-
450585
// Link to full sample:
@@ -3490,6 +3625,43 @@ Excel.DataPivotHierarchy#name:member:
34903625

34913626
dataHierarchies.items[0].name = "Farm Sales";
34923627
dataHierarchies.items[1].name = "Wholesale";
3628+
await context.sync();
3629+
});
3630+
Excel.DataValidationErrorAlert:interface:
3631+
- >-
3632+
// Link to full sample:
3633+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/22-data-validation/data-validation.yaml
3634+
3635+
3636+
await Excel.run(async (context) => {
3637+
const sheet = context.workbook.worksheets.getItem("Decision");
3638+
const rankingRange = sheet.tables.getItem("NameOptionsTable").columns.getItem("Ranking").getDataBodyRange();
3639+
3640+
// When you are developing, it is a good practice to
3641+
// clear the dataValidation object with each run of your code.
3642+
rankingRange.dataValidation.clear();
3643+
3644+
let greaterThanZeroRule = {
3645+
wholeNumber: {
3646+
formula1: 0,
3647+
operator: Excel.DataValidationOperator.greaterThan
3648+
}
3649+
};
3650+
rankingRange.dataValidation.rule = greaterThanZeroRule;
3651+
3652+
rankingRange.dataValidation.prompt = {
3653+
message: "Please enter a positive number.",
3654+
showPrompt: true,
3655+
title: "Positive numbers only."
3656+
};
3657+
3658+
rankingRange.dataValidation.errorAlert = {
3659+
message: "Sorry, only positive numbers are allowed",
3660+
showAlert: true,
3661+
style: "Stop",
3662+
title: "Negative Number Entered"
3663+
};
3664+
34933665
await context.sync();
34943666
});
34953667
Excel.DataValidation#errorAlert:member:
@@ -3835,6 +4007,64 @@ Excel.DynamicFilterCriteria:enum:
38354007

38364008
await context.sync();
38374009
});
4010+
Excel.EntityCardLayout:interface:
4011+
- >-
4012+
// Link to full sample:
4013+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml
4014+
4015+
4016+
function makeProductEntity(productID: number, productName: string, product?:
4017+
any) {
4018+
const entity: Excel.EntityCellValue = {
4019+
type: Excel.CellValueType.entity,
4020+
text: productName,
4021+
properties: { /* Excel.EntityPropertyType */
4022+
"Product ID": {
4023+
type: Excel.CellValueType.string,
4024+
basicValue: productID.toString() || ""
4025+
},
4026+
"Product Name": {
4027+
type: Excel.CellValueType.string,
4028+
basicValue: productName || ""
4029+
},
4030+
"Quantity Per Unit": {
4031+
type: Excel.CellValueType.string,
4032+
basicValue: product.quantityPerUnit || ""
4033+
},
4034+
// Add Unit Price as a formatted number.
4035+
"Unit Price": {
4036+
type: Excel.CellValueType.formattedNumber,
4037+
basicValue: product.unitPrice,
4038+
numberFormat: "$* #,##0.00"
4039+
}
4040+
},
4041+
layouts: { /* Excel.EntityViewLayouts */
4042+
card: { /* Excel.EntityCardLayout */
4043+
title: { property: "Product Name" },
4044+
sections: [ /* Excel.CardLayoutSection */
4045+
{
4046+
layout: "List",
4047+
properties: ["Product ID"]
4048+
},
4049+
{
4050+
layout: "List",
4051+
title: "Quantity and price",
4052+
collapsible: true,
4053+
collapsed: false,
4054+
properties: ["Quantity Per Unit", "Unit Price"]
4055+
}
4056+
]
4057+
}
4058+
},
4059+
provider: {
4060+
description: product.providerName, // Name of the data provider. Displays as a tooltip when hovering over the logo. Also displays as a fallback if the source address for the image is broken.
4061+
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
4062+
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
4063+
}
4064+
};
4065+
4066+
return entity;
4067+
}
38384068
Excel.EntityCompactLayoutIcons:enum:
38394069
- >-
38404070
// Link to full sample:
@@ -3864,6 +4094,122 @@ Excel.EntityCompactLayoutIcons:enum:
38644094
});
38654095
return entities;
38664096
}
4097+
Excel.EntityPropertyType:type:
4098+
- >-
4099+
// Link to full sample:
4100+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml
4101+
4102+
4103+
function makeProductEntity(productID: number, productName: string, product?:
4104+
any) {
4105+
const entity: Excel.EntityCellValue = {
4106+
type: Excel.CellValueType.entity,
4107+
text: productName,
4108+
properties: { /* Excel.EntityPropertyType */
4109+
"Product ID": {
4110+
type: Excel.CellValueType.string,
4111+
basicValue: productID.toString() || ""
4112+
},
4113+
"Product Name": {
4114+
type: Excel.CellValueType.string,
4115+
basicValue: productName || ""
4116+
},
4117+
"Quantity Per Unit": {
4118+
type: Excel.CellValueType.string,
4119+
basicValue: product.quantityPerUnit || ""
4120+
},
4121+
// Add Unit Price as a formatted number.
4122+
"Unit Price": {
4123+
type: Excel.CellValueType.formattedNumber,
4124+
basicValue: product.unitPrice,
4125+
numberFormat: "$* #,##0.00"
4126+
}
4127+
},
4128+
layouts: { /* Excel.EntityViewLayouts */
4129+
card: { /* Excel.EntityCardLayout */
4130+
title: { property: "Product Name" },
4131+
sections: [ /* Excel.CardLayoutSection */
4132+
{
4133+
layout: "List",
4134+
properties: ["Product ID"]
4135+
},
4136+
{
4137+
layout: "List",
4138+
title: "Quantity and price",
4139+
collapsible: true,
4140+
collapsed: false,
4141+
properties: ["Quantity Per Unit", "Unit Price"]
4142+
}
4143+
]
4144+
}
4145+
},
4146+
provider: {
4147+
description: product.providerName, // Name of the data provider. Displays as a tooltip when hovering over the logo. Also displays as a fallback if the source address for the image is broken.
4148+
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
4149+
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
4150+
}
4151+
};
4152+
4153+
return entity;
4154+
}
4155+
Excel.EntityViewLayouts:interface:
4156+
- >-
4157+
// Link to full sample:
4158+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml
4159+
4160+
4161+
function makeProductEntity(productID: number, productName: string, product?:
4162+
any) {
4163+
const entity: Excel.EntityCellValue = {
4164+
type: Excel.CellValueType.entity,
4165+
text: productName,
4166+
properties: { /* Excel.EntityPropertyType */
4167+
"Product ID": {
4168+
type: Excel.CellValueType.string,
4169+
basicValue: productID.toString() || ""
4170+
},
4171+
"Product Name": {
4172+
type: Excel.CellValueType.string,
4173+
basicValue: productName || ""
4174+
},
4175+
"Quantity Per Unit": {
4176+
type: Excel.CellValueType.string,
4177+
basicValue: product.quantityPerUnit || ""
4178+
},
4179+
// Add Unit Price as a formatted number.
4180+
"Unit Price": {
4181+
type: Excel.CellValueType.formattedNumber,
4182+
basicValue: product.unitPrice,
4183+
numberFormat: "$* #,##0.00"
4184+
}
4185+
},
4186+
layouts: { /* Excel.EntityViewLayouts */
4187+
card: { /* Excel.EntityCardLayout */
4188+
title: { property: "Product Name" },
4189+
sections: [ /* Excel.CardLayoutSection */
4190+
{
4191+
layout: "List",
4192+
properties: ["Product ID"]
4193+
},
4194+
{
4195+
layout: "List",
4196+
title: "Quantity and price",
4197+
collapsible: true,
4198+
collapsed: false,
4199+
properties: ["Quantity Per Unit", "Unit Price"]
4200+
}
4201+
]
4202+
}
4203+
},
4204+
provider: {
4205+
description: product.providerName, // Name of the data provider. Displays as a tooltip when hovering over the logo. Also displays as a fallback if the source address for the image is broken.
4206+
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
4207+
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
4208+
}
4209+
};
4210+
4211+
return entity;
4212+
}
38674213
Excel.ErrorCellValue:type:
38684214
- >-
38694215
// Link to full sample:

0 commit comments

Comments
 (0)