Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ script:
const entity: Excel.EntityCellValue = {
type: Excel.CellValueType.entity,
text: productName,
properties: {
properties: { /* Excel.EntityPropertyType */
"Product ID": {
type: Excel.CellValueType.string,
basicValue: productID.toString() || ""
Expand All @@ -70,10 +70,10 @@ script:
numberFormat: "$* #,##0.00"
}
},
layouts: {
card: {
layouts: { /* Excel.EntityViewLayouts */
card: { /* Excel.EntityCardLayout */
title: { property: "Product Name" },
sections: [
sections: [ /* Excel.CardLayoutSection */
{
layout: "List",
properties: ["Product ID"]
Expand Down
Binary file modified snippet-extractor-metadata/excel.xlsx
Binary file not shown.
346 changes: 346 additions & 0 deletions snippet-extractor-output/snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,141 @@ Excel.CalculationType:enum:
context.application.calculate(Excel.CalculationType.recalculate);
await context.sync();
});
Excel.CardLayoutSection:type:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this snippet is so large, it'll be hard to find the relevant section. Is all this context necessary, or it is an artifact of the way the snippet mapping works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I updated the PR and mapped CardLayoutSection to a different, shorter snippet. I also mapped EntityPropertyType and EntityViewLayouts (others in this PR) to the shorter snippet.

- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml


function makeProductEntity(productID: number, productName: string, product?:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the actual CardLayoutSection in this sample? It's not obvious (to me) from skimming the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feedback! I added the explicit types as inline comments. Please take a look and let me know what you think.

any) {
const entity: Excel.EntityCellValue = {
type: Excel.CellValueType.entity,
text: productName,
properties: { /* Excel.EntityPropertyType */
"Product ID": {
type: Excel.CellValueType.string,
basicValue: productID.toString() || ""
},
"Product Name": {
type: Excel.CellValueType.string,
basicValue: productName || ""
},
"Quantity Per Unit": {
type: Excel.CellValueType.string,
basicValue: product.quantityPerUnit || ""
},
// Add Unit Price as a formatted number.
"Unit Price": {
type: Excel.CellValueType.formattedNumber,
basicValue: product.unitPrice,
numberFormat: "$* #,##0.00"
}
},
layouts: { /* Excel.EntityViewLayouts */
card: { /* Excel.EntityCardLayout */
title: { property: "Product Name" },
sections: [ /* Excel.CardLayoutSection */
{
layout: "List",
properties: ["Product ID"]
},
{
layout: "List",
title: "Quantity and price",
collapsible: true,
collapsed: false,
properties: ["Quantity Per Unit", "Unit Price"]
}
]
}
},
provider: {
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.
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
}
};

return entity;
}
Excel.CellBorder:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/cell-properties.yaml


await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();

// Creating the SettableCellProperties objects to use for the range.
// In your add-in, these should be created once, outside the function.
const topHeaderProps: Excel.SettableCellProperties = {
// The style property takes a string matching the name of an Excel style.
// Built-in style names are listed in the `BuiltInStyle` enum.
// Note that a style will overwrite any formatting,
// so do not use the format property with the style property.
style: "Heading1"
};

const headerProps: Excel.SettableCellProperties = {
// Any subproperties of format that are not set will not be changed when these cell properties are set.
format: {
fill: {
color: "Blue"
},
font: {
color: "White",
bold: true
}
}
};

const nonApplicableProps: Excel.SettableCellProperties = {
format: {
fill: {
pattern: Excel.FillPattern.gray25
},
font: {
color: "Gray",
italic: true
}
}
};

const matchupScoreProps: Excel.SettableCellProperties = {
format: {
borders: {
bottom: {
style: Excel.BorderLineStyle.continuous
},
left: {
style: Excel.BorderLineStyle.continuous
},
right: {
style: Excel.BorderLineStyle.continuous
},
top: {
style: Excel.BorderLineStyle.continuous
}
}
}
};

const range = sheet.getRange("A1:E5");

// You can use empty JSON objects to avoid changing a cell's properties.
range.setCellProperties([
[topHeaderProps, {}, {}, {}, {}],
[{}, {}, headerProps, headerProps, headerProps],
[{}, headerProps, nonApplicableProps, matchupScoreProps, matchupScoreProps],
[{}, headerProps, matchupScoreProps, nonApplicableProps, matchupScoreProps],
[{}, headerProps, matchupScoreProps, matchupScoreProps, nonApplicableProps]
]);

sheet.getUsedRange().format.autofitColumns();
await context.sync();
});
Excel.CellControl:type:
- >-
// Link to full sample:
Expand Down Expand Up @@ -3490,6 +3625,43 @@ Excel.DataPivotHierarchy#name:member:

dataHierarchies.items[0].name = "Farm Sales";
dataHierarchies.items[1].name = "Wholesale";
await context.sync();
});
Excel.DataValidationErrorAlert:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/22-data-validation/data-validation.yaml


await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Decision");
const rankingRange = sheet.tables.getItem("NameOptionsTable").columns.getItem("Ranking").getDataBodyRange();

// When you are developing, it is a good practice to
// clear the dataValidation object with each run of your code.
rankingRange.dataValidation.clear();

let greaterThanZeroRule = {
wholeNumber: {
formula1: 0,
operator: Excel.DataValidationOperator.greaterThan
}
};
rankingRange.dataValidation.rule = greaterThanZeroRule;

rankingRange.dataValidation.prompt = {
message: "Please enter a positive number.",
showPrompt: true,
title: "Positive numbers only."
};

rankingRange.dataValidation.errorAlert = {
message: "Sorry, only positive numbers are allowed",
showAlert: true,
style: "Stop",
title: "Negative Number Entered"
};

await context.sync();
});
Excel.DataValidation#errorAlert:member:
Expand Down Expand Up @@ -3835,6 +4007,64 @@ Excel.DynamicFilterCriteria:enum:

await context.sync();
});
Excel.EntityCardLayout:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml


function makeProductEntity(productID: number, productName: string, product?:
any) {
const entity: Excel.EntityCellValue = {
type: Excel.CellValueType.entity,
text: productName,
properties: { /* Excel.EntityPropertyType */
"Product ID": {
type: Excel.CellValueType.string,
basicValue: productID.toString() || ""
},
"Product Name": {
type: Excel.CellValueType.string,
basicValue: productName || ""
},
"Quantity Per Unit": {
type: Excel.CellValueType.string,
basicValue: product.quantityPerUnit || ""
},
// Add Unit Price as a formatted number.
"Unit Price": {
type: Excel.CellValueType.formattedNumber,
basicValue: product.unitPrice,
numberFormat: "$* #,##0.00"
}
},
layouts: { /* Excel.EntityViewLayouts */
card: { /* Excel.EntityCardLayout */
title: { property: "Product Name" },
sections: [ /* Excel.CardLayoutSection */
{
layout: "List",
properties: ["Product ID"]
},
{
layout: "List",
title: "Quantity and price",
collapsible: true,
collapsed: false,
properties: ["Quantity Per Unit", "Unit Price"]
}
]
}
},
provider: {
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.
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
}
};

return entity;
}
Excel.EntityCompactLayoutIcons:enum:
- >-
// Link to full sample:
Expand Down Expand Up @@ -3864,6 +4094,122 @@ Excel.EntityCompactLayoutIcons:enum:
});
return entities;
}
Excel.EntityPropertyType:type:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml


function makeProductEntity(productID: number, productName: string, product?:
any) {
const entity: Excel.EntityCellValue = {
type: Excel.CellValueType.entity,
text: productName,
properties: { /* Excel.EntityPropertyType */
"Product ID": {
type: Excel.CellValueType.string,
basicValue: productID.toString() || ""
},
"Product Name": {
type: Excel.CellValueType.string,
basicValue: productName || ""
},
"Quantity Per Unit": {
type: Excel.CellValueType.string,
basicValue: product.quantityPerUnit || ""
},
// Add Unit Price as a formatted number.
"Unit Price": {
type: Excel.CellValueType.formattedNumber,
basicValue: product.unitPrice,
numberFormat: "$* #,##0.00"
}
},
layouts: { /* Excel.EntityViewLayouts */
card: { /* Excel.EntityCardLayout */
title: { property: "Product Name" },
sections: [ /* Excel.CardLayoutSection */
{
layout: "List",
properties: ["Product ID"]
},
{
layout: "List",
title: "Quantity and price",
collapsible: true,
collapsed: false,
properties: ["Quantity Per Unit", "Unit Price"]
}
]
}
},
provider: {
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.
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
}
};

return entity;
}
Excel.EntityViewLayouts:interface:
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-attribution.yaml


function makeProductEntity(productID: number, productName: string, product?:
any) {
const entity: Excel.EntityCellValue = {
type: Excel.CellValueType.entity,
text: productName,
properties: { /* Excel.EntityPropertyType */
"Product ID": {
type: Excel.CellValueType.string,
basicValue: productID.toString() || ""
},
"Product Name": {
type: Excel.CellValueType.string,
basicValue: productName || ""
},
"Quantity Per Unit": {
type: Excel.CellValueType.string,
basicValue: product.quantityPerUnit || ""
},
// Add Unit Price as a formatted number.
"Unit Price": {
type: Excel.CellValueType.formattedNumber,
basicValue: product.unitPrice,
numberFormat: "$* #,##0.00"
}
},
layouts: { /* Excel.EntityViewLayouts */
card: { /* Excel.EntityCardLayout */
title: { property: "Product Name" },
sections: [ /* Excel.CardLayoutSection */
{
layout: "List",
properties: ["Product ID"]
},
{
layout: "List",
title: "Quantity and price",
collapsible: true,
collapsed: false,
properties: ["Quantity Per Unit", "Unit Price"]
}
]
}
},
provider: {
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.
logoSourceAddress: product.sourceAddress, // Source URL of the logo to display.
logoTargetAddress: product.targetAddress // Destination URL that the logo navigates to when clicked.
}
};

return entity;
}
Excel.ErrorCellValue:type:
- >-
// Link to full sample:
Expand Down