Skip to content

Instantly share code, notes, and snippets.

@smozgur
Last active February 5, 2023 13:25
Show Gist options
  • Save smozgur/dab91373d837cb29914bf2793f8c8e13 to your computer and use it in GitHub Desktop.
Save smozgur/dab91373d837cb29914bf2793f8c8e13 to your computer and use it in GitHub Desktop.
Generates a list of sequential numbers with transpose option
name: Excel Custom Function
description: Generates a list of sequential numbers with transpose option
host: EXCEL
api_set: {}
script:
content: >
/**
* Excel Custom SEQUENCE function
* Generates a list of sequential numbers
* with transpose option
*
* @customfunction
* @params {number} rows
* @params {number} [columns]
* @params {number} [start]
* @params {number} [step]
* @params {boolean} [transpose]
*
* @return {number[][]}
*/
function CF_SEQUENCE(rows: number, columns?: number, start?: number, step?:
number, transpose?: boolean) {
const error = new CustomFunctions.Error(CustomFunctions.ErrorCode.invalidValue);
if (rows < 1) {
return error;
}
columns = columns || 1;
start = start ?? 1;
step = step || 1;
const rng = [];
if (transpose) {
[rows, columns] = [columns, rows]
}
for (var i = 0; i < rows; i++) {
rng[i] = [];
for (var j = 0; j < columns; j++) {
rng[i][j] = start;
start = start + step;
}
}
return rng;
}
language: typescript
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment