Skip to content

[Excel] (Custom functions) Switch formatted numbers to doubles #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions playlists-prod/excel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@
group: Custom XML Parts
api_set:
ExcelApi: '1.5'
- id: excel-data-types-formatted-number
name: 'Data types: Formatted numbers'
- id: excel-data-types-doubles
name: 'Data types: Doubles'
fileName: data-types-formatted-number.yaml
description: >-
This sample shows how to set and get data types using the formatted number
properties.
This sample shows how to set and get formatted numbers using double data
types.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
group: Data Types
Expand Down
8 changes: 4 additions & 4 deletions playlists/excel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@
group: Custom XML Parts
api_set:
ExcelApi: '1.5'
- id: excel-data-types-formatted-number
name: 'Data types: Formatted numbers'
- id: excel-data-types-doubles
name: 'Data types: Doubles'
fileName: data-types-formatted-number.yaml
description: >-
This sample shows how to set and get data types using the formatted number
properties.
This sample shows how to set and get formatted numbers using double data
types.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml
group: Data Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ script:
},
// Add Unit Price as a formatted number.
"Unit Price": {
type: "FormattedNumber",
type: "Double",
basicValue: product.unitPrice,
numberFormat: "$* #,##0.00"
},
Expand Down
38 changes: 19 additions & 19 deletions samples/excel/20-data-types/data-types-formatted-number.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
order: 1
id: excel-data-types-formatted-number
name: 'Data types: Formatted numbers'
description: This sample shows how to set and get data types using the formatted number properties.
id: excel-data-types-doubles
name: 'Data types: Doubles'
description: This sample shows how to set and get formatted numbers using double data types.
host: EXCEL
api_set:
ExcelApi: '1.16'
script:
content: |-
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
document.getElementById("set-formatted-number-date").addEventListener("click", () => tryCatch(setFormattedNumberDate));
document.getElementById("set-formatted-number-currency").addEventListener("click", () => tryCatch(setFormattedNumberCurrency));
document.getElementById("get-formatted-number").addEventListener("click", () => tryCatch(getFormattedNumber));
document.getElementById("set-double-as-date").addEventListener("click", () => tryCatch(setDoubleAsDate));
document.getElementById("set-double-as-currency").addEventListener("click", () => tryCatch(setDoubleAsCurrency));
document.getElementById("get-double").addEventListener("click", () => tryCatch(getDouble));

async function setFormattedNumberDate() {
// This function creates a formatted number data type,
async function setDoubleAsDate() {
// This function creates a double data type,
// and sets the format of this data type as a date.
await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
Expand All @@ -24,7 +24,7 @@ script:
dateRange.valuesAsJson = [
[
{
type: Excel.CellValueType.formattedNumber,
type: Excel.CellValueType.double,
basicValue: 32889.0,
numberFormat: "m/d/yyyy"
}
Expand All @@ -34,8 +34,8 @@ script:
});
}

async function setFormattedNumberCurrency() {
// This function creates a formatted number data type,
async function setDoubleAsCurrency() {
// This function creates a double data type,
// and sets the format of this data type as a currency.
await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
Expand All @@ -46,7 +46,7 @@ script:
currencyRange.valuesAsJson = [
[
{
type: Excel.CellValueType.formattedNumber,
type: Excel.CellValueType.double,
basicValue: 12.34,
numberFormat: "$* #,##0.00"
}
Expand All @@ -57,7 +57,7 @@ script:
});
}

async function getFormattedNumber() {
async function getDouble() {
// This function prints information about data types
// in cells A1 and A2 to the console.
await Excel.run(async (context) => {
Expand All @@ -79,13 +79,13 @@ script:
console.log(" Type: " + dateValues.type);
console.log(" Basic value: " + dateValues.basicValue);
console.log(" Basic type: " + dateValues.basicType);
console.log(" Number format: " + (dateValues as Excel.FormattedNumberCellValue).numberFormat);
console.log(" Number format: " + (dateValues as Excel.DoubleCellValue).numberFormat);

console.log("Currency");
console.log(" Type: " + currencyValues.type);
console.log(" Basic value: " + currencyValues.basicValue);
console.log(" Basic type: " + currencyValues.basicType);
console.log(" Number format: " + (currencyValues as Excel.FormattedNumberCellValue).numberFormat);
console.log(" Number format: " + (currencyValues as Excel.DoubleCellValue).numberFormat);
});
}

Expand All @@ -111,21 +111,21 @@ script:
template:
content: |-
<section class="ms-Fabric ms-font-m">
<p>This sample shows how to work with the formatted number data type.</p>
<p>This sample shows how to work with double data types to create formatted numbers.</p>
</section>
<section class="ms-Fabric setup ms-font-m">
<h3>Set up</h3>
<button id="setup" class="ms-Button">
<span class="ms-Button-label">Add worksheet</span>
</button>
<h3>Try it out</h3>
<button id="set-formatted-number-date" class="ms-Button">
<button id="set-double-as-date" class="ms-Button">
<span class="ms-Button-label">Set formatted date</span>
</button>
<button id="set-formatted-number-currency" class="ms-Button">
<button id="set-double-as-currency" class="ms-Button">
<span class="ms-Button-label">Set formatted currency</span>
</button>
<button id="get-formatted-number" class="ms-Button">
<button id="get-double" class="ms-Button">
<span class="ms-Button-label">Log data types</span>
</button>
</section>
Expand Down
Binary file modified snippet-extractor-metadata/excel.xlsx
Binary file not shown.
114 changes: 57 additions & 57 deletions snippet-extractor-output/snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3455,6 +3455,61 @@
console.log(`${property.key}:${property.value}`);
});
});
'Excel.DoubleCellValue#numberFormat:member':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml


// This function creates a double data type,

// and sets the format of this data type as a currency.

await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
const currencyRange = sheet.getRange("A2");

// Write a number formatted as currency to cell A2.
currencyRange.valuesAsJson = [
[
{
type: Excel.CellValueType.double,
basicValue: 12.34,
numberFormat: "$* #,##0.00"
}
]
];

await context.sync();
});
'Excel.DoubleCellValue#type:member':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml


// This function creates a double data type,

// and sets the format of this data type as a date.

await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
const dateRange = sheet.getRange("A1");

// Write a number formatted as a date to cell A1.
dateRange.valuesAsJson = [
[
{
type: Excel.CellValueType.double,
basicValue: 32889.0,
numberFormat: "m/d/yyyy"
}
]
];
await context.sync();
});
'Excel.DynamicFilterCriteria:enum':
- >-
// Link to full sample:
Expand Down Expand Up @@ -3688,61 +3743,6 @@
};
filterField.applyFilter({ dateFilter: dateFilter });

await context.sync();
});
'Excel.FormattedNumberCellValue#numberFormat:member':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml


// This function creates a formatted number data type,

// and sets the format of this data type as a currency.

await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
const currencyRange = sheet.getRange("A2");

// Write a number formatted as currency to cell A2.
currencyRange.valuesAsJson = [
[
{
type: Excel.CellValueType.formattedNumber,
basicValue: 12.34,
numberFormat: "$* #,##0.00"
}
]
];

await context.sync();
});
'Excel.FormattedNumberCellValue#type:member':
- >-
// Link to full sample:
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml


// This function creates a formatted number data type,

// and sets the format of this data type as a date.

await Excel.run(async (context) => {
// Get the Sample worksheet and a range on that sheet.
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
const dateRange = sheet.getRange("A1");

// Write a number formatted as a date to cell A1.
dateRange.valuesAsJson = [
[
{
type: Excel.CellValueType.formattedNumber,
basicValue: 32889.0,
numberFormat: "m/d/yyyy"
}
]
];
await context.sync();
});
'Excel.Functions:class':
Expand Down Expand Up @@ -5940,7 +5940,7 @@
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml


// This function creates a formatted number data type,
// This function creates a double data type,

// and sets the format of this data type as a date.

Expand All @@ -5953,7 +5953,7 @@
dateRange.valuesAsJson = [
[
{
type: Excel.CellValueType.formattedNumber,
type: Excel.CellValueType.double,
basicValue: 32889.0,
numberFormat: "m/d/yyyy"
}
Expand Down
2 changes: 1 addition & 1 deletion view-prod/excel.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"excel-custom-xml-parts-create-set-get-and-delete-custom-xml-parts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml",
"excel-custom-xml-parts-test-xml-for-unique-namespace": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/test-xml-for-unique-namespace.yaml",
"excel-chart-chart-title-ts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/private-samples/excel/20-chart/chart-title-ts.yaml",
"excel-data-types-formatted-number": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml",
"excel-data-types-doubles": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml",
"excel-data-types-web-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-web-image.yaml",
"excel-data-types-entity-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-values.yaml",
"excel-data-types-error-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-error-values.yaml",
Expand Down
2 changes: 1 addition & 1 deletion view/excel.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"excel-custom-xml-parts-create-set-get-and-delete-custom-xml-parts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml",
"excel-custom-xml-parts-test-xml-for-unique-namespace": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/18-custom-xml-parts/test-xml-for-unique-namespace.yaml",
"excel-chart-chart-title-ts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/private-samples/excel/20-chart/chart-title-ts.yaml",
"excel-data-types-formatted-number": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml",
"excel-data-types-doubles": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml",
"excel-data-types-web-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-web-image.yaml",
"excel-data-types-entity-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-entity-values.yaml",
"excel-data-types-error-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-error-values.yaml",
Expand Down