Skip to content

Commit

Permalink
ADD word definitions macro sample
Browse files Browse the repository at this point in the history
  • Loading branch information
eeshaansawant committed Dec 17, 2024
1 parent 61ae0b1 commit 8e8dc02
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- docspace backend: added the Removed user page
- macros: added remove extra spaces in document macro sample
- macros: added the Sum of highlighted cells 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,51 @@
---
order:
---

## Description

Generate definitions for your words in your document.

<!-- 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

## Reference Microsoft VBA macro code

<!-- code generated with AI -->

```vb
```

## Result

<!-- imgpath -->

![Generate word definitons](/assets/images/plugins/generate-word-defintions.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 @@ -142,6 +142,12 @@ In this example we are summing the answer of all highlighted cells in a spreadsh

[More](Sum%20of%20Highlighted%20Cells/index.md)

## Generate word definitions

In this example we are generating word definitions in our documents.

[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 8e8dc02

Please sign in to comment.