Skip to content

Commit 69d116c

Browse files
authored
[Excel] (Custom functions) Switch formatted numbers to doubles (#987)
* [Excel] (Custom functions) Switch formatted numbers to doubles * Run yarn start * Adjust title to emphasize purpose of sample
1 parent 6357648 commit 69d116c

File tree

8 files changed

+84
-84
lines changed

8 files changed

+84
-84
lines changed

playlists-prod/excel.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@
305305
group: Custom XML Parts
306306
api_set:
307307
ExcelApi: '1.5'
308-
- id: excel-data-types-formatted-number
308+
- id: excel-data-types-doubles
309309
name: 'Data types: Formatted numbers'
310310
fileName: data-types-formatted-number.yaml
311311
description: >-
312-
This sample shows how to set and get data types using the formatted number
313-
properties.
312+
This sample shows how to set and get formatted numbers using double data
313+
types.
314314
rawUrl: >-
315315
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
316316
group: Data Types

playlists/excel.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@
305305
group: Custom XML Parts
306306
api_set:
307307
ExcelApi: '1.5'
308-
- id: excel-data-types-formatted-number
308+
- id: excel-data-types-doubles
309309
name: 'Data types: Formatted numbers'
310310
fileName: data-types-formatted-number.yaml
311311
description: >-
312-
This sample shows how to set and get data types using the formatted number
313-
properties.
312+
This sample shows how to set and get formatted numbers using double data
313+
types.
314314
rawUrl: >-
315315
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml
316316
group: Data Types

samples/excel/16-custom-functions/data-types-custom-functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ script:
6666
},
6767
// Add Unit Price as a formatted number.
6868
"Unit Price": {
69-
type: "FormattedNumber",
69+
type: "Double",
7070
basicValue: product.unitPrice,
7171
numberFormat: "$* #,##0.00"
7272
},

samples/excel/20-data-types/data-types-formatted-number.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
order: 1
2-
id: excel-data-types-formatted-number
2+
id: excel-data-types-doubles
33
name: 'Data types: Formatted numbers'
4-
description: This sample shows how to set and get data types using the formatted number properties.
4+
description: This sample shows how to set and get formatted numbers using double data types.
55
host: EXCEL
66
api_set:
77
ExcelApi: '1.16'
88
script:
99
content: |-
1010
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
11-
document.getElementById("set-formatted-number-date").addEventListener("click", () => tryCatch(setFormattedNumberDate));
12-
document.getElementById("set-formatted-number-currency").addEventListener("click", () => tryCatch(setFormattedNumberCurrency));
13-
document.getElementById("get-formatted-number").addEventListener("click", () => tryCatch(getFormattedNumber));
11+
document.getElementById("set-double-as-date").addEventListener("click", () => tryCatch(setDoubleAsDate));
12+
document.getElementById("set-double-as-currency").addEventListener("click", () => tryCatch(setDoubleAsCurrency));
13+
document.getElementById("get-double").addEventListener("click", () => tryCatch(getDouble));
1414
15-
async function setFormattedNumberDate() {
16-
// This function creates a formatted number data type,
15+
async function setDoubleAsDate() {
16+
// This function creates a double data type,
1717
// and sets the format of this data type as a date.
1818
await Excel.run(async (context) => {
1919
// Get the Sample worksheet and a range on that sheet.
@@ -24,7 +24,7 @@ script:
2424
dateRange.valuesAsJson = [
2525
[
2626
{
27-
type: Excel.CellValueType.formattedNumber,
27+
type: Excel.CellValueType.double,
2828
basicValue: 32889.0,
2929
numberFormat: "m/d/yyyy"
3030
}
@@ -34,8 +34,8 @@ script:
3434
});
3535
}
3636
37-
async function setFormattedNumberCurrency() {
38-
// This function creates a formatted number data type,
37+
async function setDoubleAsCurrency() {
38+
// This function creates a double data type,
3939
// and sets the format of this data type as a currency.
4040
await Excel.run(async (context) => {
4141
// Get the Sample worksheet and a range on that sheet.
@@ -46,7 +46,7 @@ script:
4646
currencyRange.valuesAsJson = [
4747
[
4848
{
49-
type: Excel.CellValueType.formattedNumber,
49+
type: Excel.CellValueType.double,
5050
basicValue: 12.34,
5151
numberFormat: "$* #,##0.00"
5252
}
@@ -57,7 +57,7 @@ script:
5757
});
5858
}
5959
60-
async function getFormattedNumber() {
60+
async function getDouble() {
6161
// This function prints information about data types
6262
// in cells A1 and A2 to the console.
6363
await Excel.run(async (context) => {
@@ -79,13 +79,13 @@ script:
7979
console.log(" Type: " + dateValues.type);
8080
console.log(" Basic value: " + dateValues.basicValue);
8181
console.log(" Basic type: " + dateValues.basicType);
82-
console.log(" Number format: " + (dateValues as Excel.FormattedNumberCellValue).numberFormat);
82+
console.log(" Number format: " + (dateValues as Excel.DoubleCellValue).numberFormat);
8383
8484
console.log("Currency");
8585
console.log(" Type: " + currencyValues.type);
8686
console.log(" Basic value: " + currencyValues.basicValue);
8787
console.log(" Basic type: " + currencyValues.basicType);
88-
console.log(" Number format: " + (currencyValues as Excel.FormattedNumberCellValue).numberFormat);
88+
console.log(" Number format: " + (currencyValues as Excel.DoubleCellValue).numberFormat);
8989
});
9090
}
9191
@@ -111,21 +111,21 @@ script:
111111
template:
112112
content: |-
113113
<section class="ms-Fabric ms-font-m">
114-
<p>This sample shows how to work with the formatted number data type.</p>
114+
<p>This sample shows how to work with double data types to create formatted numbers.</p>
115115
</section>
116116
<section class="ms-Fabric setup ms-font-m">
117117
<h3>Set up</h3>
118118
<button id="setup" class="ms-Button">
119119
<span class="ms-Button-label">Add worksheet</span>
120120
</button>
121121
<h3>Try it out</h3>
122-
<button id="set-formatted-number-date" class="ms-Button">
122+
<button id="set-double-as-date" class="ms-Button">
123123
<span class="ms-Button-label">Set formatted date</span>
124124
</button>
125-
<button id="set-formatted-number-currency" class="ms-Button">
125+
<button id="set-double-as-currency" class="ms-Button">
126126
<span class="ms-Button-label">Set formatted currency</span>
127127
</button>
128-
<button id="get-formatted-number" class="ms-Button">
128+
<button id="get-double" class="ms-Button">
129129
<span class="ms-Button-label">Log data types</span>
130130
</button>
131131
</section>

snippet-extractor-metadata/excel.xlsx

35 Bytes
Binary file not shown.

snippet-extractor-output/snippets.yaml

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,61 @@
34553455
console.log(`${property.key}:${property.value}`);
34563456
});
34573457
});
3458+
'Excel.DoubleCellValue#numberFormat:member':
3459+
- >-
3460+
// Link to full sample:
3461+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
3462+
3463+
3464+
// This function creates a double data type,
3465+
3466+
// and sets the format of this data type as a currency.
3467+
3468+
await Excel.run(async (context) => {
3469+
// Get the Sample worksheet and a range on that sheet.
3470+
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
3471+
const currencyRange = sheet.getRange("A2");
3472+
3473+
// Write a number formatted as currency to cell A2.
3474+
currencyRange.valuesAsJson = [
3475+
[
3476+
{
3477+
type: Excel.CellValueType.double,
3478+
basicValue: 12.34,
3479+
numberFormat: "$* #,##0.00"
3480+
}
3481+
]
3482+
];
3483+
3484+
await context.sync();
3485+
});
3486+
'Excel.DoubleCellValue#type:member':
3487+
- >-
3488+
// Link to full sample:
3489+
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
3490+
3491+
3492+
// This function creates a double data type,
3493+
3494+
// and sets the format of this data type as a date.
3495+
3496+
await Excel.run(async (context) => {
3497+
// Get the Sample worksheet and a range on that sheet.
3498+
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
3499+
const dateRange = sheet.getRange("A1");
3500+
3501+
// Write a number formatted as a date to cell A1.
3502+
dateRange.valuesAsJson = [
3503+
[
3504+
{
3505+
type: Excel.CellValueType.double,
3506+
basicValue: 32889.0,
3507+
numberFormat: "m/d/yyyy"
3508+
}
3509+
]
3510+
];
3511+
await context.sync();
3512+
});
34583513
'Excel.DynamicFilterCriteria:enum':
34593514
- >-
34603515
// Link to full sample:
@@ -3688,61 +3743,6 @@
36883743
};
36893744
filterField.applyFilter({ dateFilter: dateFilter });
36903745

3691-
await context.sync();
3692-
});
3693-
'Excel.FormattedNumberCellValue#numberFormat:member':
3694-
- >-
3695-
// Link to full sample:
3696-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
3697-
3698-
3699-
// This function creates a formatted number data type,
3700-
3701-
// and sets the format of this data type as a currency.
3702-
3703-
await Excel.run(async (context) => {
3704-
// Get the Sample worksheet and a range on that sheet.
3705-
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
3706-
const currencyRange = sheet.getRange("A2");
3707-
3708-
// Write a number formatted as currency to cell A2.
3709-
currencyRange.valuesAsJson = [
3710-
[
3711-
{
3712-
type: Excel.CellValueType.formattedNumber,
3713-
basicValue: 12.34,
3714-
numberFormat: "$* #,##0.00"
3715-
}
3716-
]
3717-
];
3718-
3719-
await context.sync();
3720-
});
3721-
'Excel.FormattedNumberCellValue#type:member':
3722-
- >-
3723-
// Link to full sample:
3724-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
3725-
3726-
3727-
// This function creates a formatted number data type,
3728-
3729-
// and sets the format of this data type as a date.
3730-
3731-
await Excel.run(async (context) => {
3732-
// Get the Sample worksheet and a range on that sheet.
3733-
const sheet = context.workbook.worksheets.getItemOrNullObject("Sample");
3734-
const dateRange = sheet.getRange("A1");
3735-
3736-
// Write a number formatted as a date to cell A1.
3737-
dateRange.valuesAsJson = [
3738-
[
3739-
{
3740-
type: Excel.CellValueType.formattedNumber,
3741-
basicValue: 32889.0,
3742-
numberFormat: "m/d/yyyy"
3743-
}
3744-
]
3745-
];
37463746
await context.sync();
37473747
});
37483748
'Excel.Functions:class':
@@ -5940,7 +5940,7 @@
59405940
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml
59415941

59425942

5943-
// This function creates a formatted number data type,
5943+
// This function creates a double data type,
59445944

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

@@ -5953,7 +5953,7 @@
59535953
dateRange.valuesAsJson = [
59545954
[
59555955
{
5956-
type: Excel.CellValueType.formattedNumber,
5956+
type: Excel.CellValueType.double,
59575957
basicValue: 32889.0,
59585958
numberFormat: "m/d/yyyy"
59595959
}

view-prod/excel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"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",
3434
"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",
3535
"excel-chart-chart-title-ts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/private-samples/excel/20-chart/chart-title-ts.yaml",
36-
"excel-data-types-formatted-number": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml",
36+
"excel-data-types-doubles": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml",
3737
"excel-data-types-web-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-web-image.yaml",
3838
"excel-data-types-entity-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-entity-values.yaml",
3939
"excel-data-types-error-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-error-values.yaml",

view/excel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"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",
3434
"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",
3535
"excel-chart-chart-title-ts": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/private-samples/excel/20-chart/chart-title-ts.yaml",
36-
"excel-data-types-formatted-number": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml",
36+
"excel-data-types-doubles": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-formatted-number.yaml",
3737
"excel-data-types-web-image": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-web-image.yaml",
3838
"excel-data-types-entity-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-entity-values.yaml",
3939
"excel-data-types-error-values": "https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/excel/20-data-types/data-types-error-values.yaml",

0 commit comments

Comments
 (0)