-
Notifications
You must be signed in to change notification settings - Fork 126
[Excel] (Custom Functions) Sample for using custom enum in custom function #988
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
Merged
alison-mk
merged 3 commits into
OfficeDev:main
from
donlvMSFT:user/donlv/updateCFSample
Jun 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
samples/excel/16-custom-functions/custom-enum-function.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
order: 7 | ||
id: excel-custom-functions-custom-enum-function | ||
name: Function with custom enum parameters | ||
description: Use custom enum as parameters in custom functions for searching flights. | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
host: EXCEL | ||
api_set: | ||
CustomFunctionsRuntime: '1.5' | ||
script: | ||
content: | | ||
/** | ||
* Enum representing different airports. | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @customenum {string} | ||
*/ | ||
enum AirPorts { | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Beijing is the capital of China. | ||
Beijing = "PEK", | ||
|
||
// Shanghai is a major financial hub in China. | ||
Shanghai = "PVG", | ||
|
||
// Seattle is known for its tech industry and the Space Needle. | ||
Seattle = "SEA", | ||
|
||
// San Francisco is famous for the Golden Gate Bridge and tech startups. | ||
SanFrancisco = "SFO", | ||
|
||
// Tokyo is the capital of Japan and known for its modern architecture and culture. | ||
Tokyo = "HND" | ||
} | ||
|
||
/** | ||
* Enum representing the days of the week. | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @customenum {number} | ||
*/ | ||
enum DayOfWeek { | ||
Monday = 1, | ||
Tuesday = 2, | ||
Wednesday = 3, | ||
Thursday = 4, | ||
Friday = 5, | ||
Saturday = 6, | ||
Sunday = 7 | ||
} | ||
|
||
/** | ||
* Function to get flight schedule. | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @customfunction | ||
* @param {AirPorts} departure where the flight departs from | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {AirPorts} destination where the flight arrives | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {DayOfWeek[]} day days of the week when the flight is available | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @returns Available flight schedule | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
function fetchFlightSchedule(departure: AirPorts, destination: AirPorts, day: DayOfWeek[]): string[][] { | ||
donlvMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const flights: string[][] = []; | ||
flights.push(["Flights from " + departure + " to " + destination, "", "", "", ""]); | ||
flights.push(["Day", "Flight Number", "Departure Time", "Arrival Time", "Price"]); | ||
const daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; | ||
|
||
day.forEach((d) => { | ||
const dayName = daysOfWeek[d - 1]; | ||
const numberOfFlights = Math.floor(Math.random() * 3) + 1; // 1 to 3 flights | ||
|
||
for (let i = 0; i < numberOfFlights; i++) { | ||
const flightNumber = `AA${Math.floor(Math.random() * 900) + 100}`; | ||
const departureTime = `${Math.floor(Math.random() * 12) + 1}:00 ${Math.random() > 0.5 ? "AM" : "PM"}`; | ||
const arrivalTime = `${Math.floor(Math.random() * 12) + 1}:00 ${Math.random() > 0.5 ? "AM" : "PM"}`; | ||
const price = `$${Math.floor(Math.random() * 500) + 100}`; | ||
|
||
flights.push([dayName, flightNumber, departureTime, arrivalTime, price]); | ||
} | ||
}); | ||
|
||
return flights; | ||
} | ||
language: typescript | ||
libraries: | | ||
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | ||
@types/office-js | ||
|
||
[email protected]/dist/css/fabric.min.css | ||
[email protected]/dist/css/fabric.components.min.css | ||
|
||
[email protected]/client/core.min.js | ||
@types/core-js | ||
|
||
[email protected] | ||
@types/[email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.