I’ve been experimenting with the JavaScript DOCX Editor and successfully got it working—I can manually type and edit text within the document.
Now, I’d like to add a custom button outside the editor that, when clicked, inserts text at the current caret position or replaces the selected text if any is highlighted.
How can I achieve this? I couldn’t find any examples or documentation covering this functionality.
The API works by pasting the content from the clipboard into the editor at the current caret position (replacing any selected text). You can use your custom button to write the desired text to the clipboard and call the pasteText() API.
Let us know if this works for you!
Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer Apryse Software Inc.
And then have a click handler that uses the OfficeEditor ref to paste in the coped text.
const placeholderText = 'Hello World';
const pasteWithFormatting = false;
// First copy the placeholder text to the clipboard
navigator.clipboard.writeText(placeholderText)
.then(() => {
// Then use the paste method from the Office Editor
officeEditor.value.pasteText(pasteWithFormatting);
console.log('Placeholder text added via clipboard paste');
})
.catch((err) => {
console.warn('Clipboard access failed', err);
});
The browser copy and paste allowed prompt is displayed for the page which must be accepted for this to work.
Do you know if there is future support for adding text / programmatically controlling the editor directly i.e. not using this copy and paste approach?
Glad to hear you were able to make the solution work for your project!
We currently do not have this feature on our backlog, but I can raise this feature request for our Product team to review for feasibility and viability.
If you could provide some further information around the context of why you want the feature, this may help prioritize its development. We would be interested to know:
What is the workflow that you would use the requested feature in?
Why is the feature valuable to you and your users?
How are you coping without it right now?
Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer Apryse Software Inc.