Skip to content

Instantly share code, notes, and snippets.

@jiju-MS
Created April 25, 2022 07:17
Show Gist options
  • Save jiju-MS/8f722c712390b743b9db64e9d13fbcf7 to your computer and use it in GitHub Desktop.
Save jiju-MS/8f722c712390b743b9db64e9d13fbcf7 to your computer and use it in GitHub Desktop.
Calculates the volume of a sphere.
name: Basic custom function
description: Calculates the volume of a sphere.
host: EXCEL
api_set: {}
script:
content: |
/**
* Calculates the volume of a sphere.
* @customfunction
* @param {number} radius
* @returns The volume of the sphere.
*/
function sphereVolume(radius) {
return (Math.pow(radius, 3) * 4 * Math.PI) / 3;
}
/**
* Calculates the volume of a sphere.
* @customfunction
* @param {number} entityCase
* @returns The volume of the sphere.
*/
function SetEntity(entityCase) {
switch (entityCase) {
case 1: {
return {
type: "Entity",
basicType: "Error",
basicValue: "#VALUE!",
text: "My Entity",
properties: {
TestDouble: { type: "Double", basicType: "Double", basicValue: 1 },
TestString: { type: "String", basicType: "String", basicValue: "Test" }
}
};
}
case 2: {
return {
type: "FormattedNumber",
basicValue: 1.23,
numberFormat: "0.00%"
};
}
case 3: {
return {
type: "WebImage",
basicType: "Error",
basicValue: "#VALUE!",
address: "https://upload.wikimedia.org/wikipedia/en/c/cd/Marioparty1.jpg"
};
}
default: {
return "Invalid test case";
}
}
}
language: typescript
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
core-js@2.4.1/client/core.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment