Skip to content

Commit

Permalink
Merge pull request 'ADD word definitions macro sample' from feature/w…
Browse files Browse the repository at this point in the history
…ord_defintions into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/api.onlyoffice.com/pulls/95
Reviewed-by: Natalia Ovchinnikova <[email protected]>
  • Loading branch information
LinneyS committed Jan 13, 2025
2 parents 76828da + 5dbd61e commit 45779c8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- macros: added hide unhide rows or columns in spreadsheet macro sample
- macros: added find company logos macro sample
- macros: added import hyperlinks in spreadsheet macro sample
- macros: added generate word definitons macro sample

## 6.3.0
- docspace oauth api: added a new section
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
order:
---

## Description

Generates word definitions in your document using the [Dictionary API](https://api-ninjas.com/api/dictionary) offered by [API Ninjas](https://api-ninjas.com).

> To use this macro, you need to obtain your own API key from API Ninjas.
<!-- This code snippet is shown in the screenshot. -->

<!-- eslint-skip -->

```ts
(function () {
const oDocument = Api.GetDocument();
const oRange = oDocument.GetRangeBySelect();
const word = oRange.GetText();
$.ajax({
method: "GET",
url: "https://api.api-ninjas.com/v1/dictionary?word=" + word,
headers: { "X-Api-Key": "your-api-key" },
contentType: "application/json",
success: function (result) {
console.log(result);
const text = result.definition;
const oParagraph = Api.CreateParagraph();
oParagraph.AddText(text);
oDocument.InsertContent([oParagraph], { KeepTextOnly: true });
},
error: function ajaxError(jqXHR) {
console.error("Error: ", jqXHR.responseText);
},
});
})();
```

Methods used: GetDocument, GetRangeBySelect, GetText, CreateParagraph, AddText, InsertContent

## Result

<!-- imgpath -->

![Generate word definitons](/assets/images/plugins/generate-word-definitions.png)
6 changes: 6 additions & 0 deletions site/pages/Docs/Plugin and Macros/Macros/Samples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ In this example we are importing hyperlinks between different worksheets in the

[More](Import%20hyperlinks/index.md)

## Generate word definitions

In this example we are generating word definitions in our documents using the Dictionary API offered by API Ninjas.

[More](Generate%20word%20definitions/index.md)

## Support

If you want to request a feature or report a bug regarding macros, use the issues section [on GitHub.](https://github.com/ONLYOFFICE/plugin-macros/issues)
Expand Down

0 comments on commit 45779c8

Please sign in to comment.