Skip to content
Merged
Changes from 1 commit
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
35 changes: 20 additions & 15 deletions docs/guide/custom-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ MyCustomPlugin.implementedFunctions = {

### 3. Add your function's names

In a separate object,
[define your function's names in every language you want to support](#function-name-translations).
In a separate object, define your function's names in every
[language](#function-name-translations) that you want to support.

::: tip
Even if you support just a single language, you still need to define a translation for it.
:::

```js
export const MyCustomPluginTranslations = {
Expand Down Expand Up @@ -127,7 +131,7 @@ export class MyCustomPlugin extends FunctionPlugin {

### 5. Register your function plugin

Register your function plugin (and its translations) so that HyperFormula can
Register your function plugin and its translations so that HyperFormula can
recognize it.

Use the
Expand All @@ -138,21 +142,23 @@ method:
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
```

### 6. Use your custom function inside a formula
### 6. Use your custom function in a formula

Now, you can use your GREET function inside a formula:
Now, you're ready to use your GREET function in a formula.

Don't forget to register your function plugin **before** you create your HyperFormula instance. Otherwise, HyperFormula won't recognize your plugin.

```js
// prepare spreadsheet data
const data = [['Anthony', '=GREET(A1)']];
// register your function plugin and its translations
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is already mentioned in step 5. Do you think it's beneficial to duplicate it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it this way: 58f0eb6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, now we have no duplication. Thanks ;)


// build a HyperFormula instance where you can use your function directly
const hfInstance = HyperFormula.buildFromArray(data);
const hfInstance = HyperFormula.buildFromArray([['Anthony', '=GREET(A1)']]);

// read the value of cell A1
// read the value of cell B1
const result = hfInstance.getCellValue({ sheet: 0, col: 1, row: 0 });

// open the browser's console to see the results
// cell B1 should evaluate to 'Anthony'
console.log(result);
```

Expand Down Expand Up @@ -478,15 +484,14 @@ function's behavior depends on the number of valid arguments passed), use the
You can add translations of your function's name in multiple languages. Your end
users use the translated names to call your function inside formulas.

::: tip
If you support just one language, you still need to define the name of
your function in that language.
:::

In a separate object, define the translations of your custom functions' names in
every language you want to support. Function names are case-insensitive, as they
are all normalized to uppercase.

::: tip
Even if you support just a single language, you still need to define a translation for it.
:::

```js
export const MyCustomPluginTranslations = {
enGB: {
Expand Down