ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

How to access the data of the spreadsheet through the ONLYOFFICE Document Builder API in the plugin? #176

Closed ChiuJun closed 1 year ago

ChiuJun commented 1 year ago

Do you want to request a feature or report a bug? feature What is the current behavior? As described in the ONLYOFFICE Plugins API Docs We can pass data one-way through Asc.scope object to the plugin code in window.Asc.plugin.callCommand method.

The object is used to pass any additional data (objects, parameters, variables, etc.) to the window.Asc.plugin.callCommand method, which is executed in its own isolated context.

And we can get the selected text when plugin run through setting variations.initDataType in the plugin configuration file.

Is usually equal to "" - this is the data which is sent from the editor to the plugin at the plugin start (e.g. if initDataType == "text", the plugin will receive the selected text when run). It may also be equal to encryption in the encryption plugins.

But I can't find any other way to get the spreadsheet data in the API Docs,this question seems to be similar to #154 .And I think the https://github.com/ONLYOFFICE/sdkjs/pull/1964 mentioned in it is a good feature. So is there any other way to access the data in the spreadsheet ?

By the way, I used the unofficial way to directly call the API instead of overriding window.Asc.plugin.callCommand method, so that my plugin can get the spreadsheet data.

// in plugin iframe
const Api = window.parent.g_asc_plugins.api;

Thanks !

l8556 commented 1 year ago

Hi @ChiuJun

You can access the data in the spreadsheet by using execute methods from the documentation, for example, can get the selected text via method: window.Asc.plugin.executeMethod("GetSelectedText", [args], callback)

Or, as you note, can get the selected text when plugin run through setting variations.initDataType in the plugin configuration file.

It is also possible to perform data actions with builder methods via window.Asc.plugin.callCommand.

ChiuJun commented 1 year ago

Hi @ChiuJun

You can access the data in the spreadsheet by using execute methods from the documentation, for example, can get the selected text via method: window.Asc.plugin.executeMethod("GetSelectedText", [args], callback)

Or, as you note, can get the selected text when plugin run through setting variations.initDataType in the plugin configuration file.

It is also possible to perform data actions with builder methods via window.Asc.plugin.callCommand.

Thank you so much @l8556

I have checked the API you mentioned(executeMethod and callCommand) before creating this issue.They all have their own limitations and cannot do what Builder API can do.

For the executeMethod API:

executeMethod(name, params, callback) → { boolean }
Name Type Description
name string The name of the specific method that must be executed.

The values allowed for its parameter name may different from Builder API, but I haven't tried the method names in the Builder API. e.g. Spreadsheet Api under the executeMethod Docs.

Name Description
AddComment Adds a comment to the workbook.
ChangeComment Changes the specified comment.
RemoveComments Removes the specified comments.

For the callCommand API:
Documentation describes that it has its own context, it seems to be via JavaScript eval()

This method is executed in its own context isolated from other JavaScript data. If some parameters or other data need to be passed to this method, use Asc.scope object.

askonev commented 1 year ago

Hi @ChiuJun! There is currently no way to get data from the plugin context for security reasons. We provide an api plugin to manipulate document data at this time. The ONLYOFFICE team is working on a solution to this problem