Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ChiuJun opened this issue Dec 18, 2022 · 3 comments
Assignees
Labels
question Issues that look for answers

Comments

@ChiuJun
Copy link

ChiuJun commented Dec 18, 2022

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 ONLYOFFICE/sdkjs#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 !

@askonev askonev self-assigned this Dec 27, 2022
@l8556
Copy link
Member

l8556 commented Jan 10, 2023

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
Copy link
Author

ChiuJun commented Feb 4, 2023

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
Copy link
Member

askonev commented Feb 7, 2023

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

@askonev askonev added the question Issues that look for answers label Feb 7, 2023
@ChiuJun ChiuJun closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers
Projects
None yet
Development

No branches or pull requests

3 participants