We can use Asc.scope object, passing parameters to the callcommand method
So what should I do if I want to get the value in callcommand from the callback of callcommand
window.Asc.plugin.callCommand(function () {
var oWorksheet = Api.GetActiveSheet();
var ActiveCell = oWorksheet.ActiveCell;
var text = ActiveCell.GetComment();
Asc.scope.text = text;
}, false, false, function (a) {
//How to get text
});
1 Like
Hello @shangshandalaohu
Could you please provide us with detailed scenario? What is your final goal? Please describe your usage scenario step-by-step.
Hello @Alexandre
First, I insert comments into the cell of the sheet through the following code
window.Asc.plugin.init = function() {
var comment = document.getElementById("textareaIDComment");
document.getElementById("buttonIDAddComment").onclick = function() {
Asc.scope.textComment = comment.value; // export variable to plugin scope
window.Asc.plugin.callCommand(function() {
var oWorksheet = Api.GetActiveSheet();
var ActiveCell = oWorksheet.ActiveCell;
ActiveCell.AddComment(Asc.scope.textComment); // past comment in active cell
}, true);
};
};
Then, I need to modify the comments of the cell through the plug-in. Step 1: select the cell. Step 2: click the plug-in I made to pop up the plug-in box. Step 3: get the comments according to the selected cell and add them to the plug-in control
Step 3 I don’t know how to operate at present
Step 3: get the comments according to the selected cell and add them to the plug-in control
Do I understand it right that you need to receive persisted comment from a cell to your plugin?
Just the opposite
I need to get the comments of the selected cells when the plugin is initialized
You can get comment from a cell like this:
this.callCommand(function () {
var oWorksheet = Api.GetActiveSheet();
var ActiveCell = oWorksheet.ActiveCell;
ActiveCell.GetComment();
}, true);
I know it can be obtained through the callcommand method, but after obtaining it, it cannot be passed to the control in the plugin. The plugin can be obtained through asc Scope passes parameters to callcommand, but callcommand cannot return values to the plugin
(function (window, undefined) {
window.Asc.plugin.init = function (text) {
window.Asc.plugin.callCommand(function () {
var oWorksheet = Api.GetActiveSheet();
var ActiveCell = oWorksheet.ActiveCell;
var text = ActiveCell.GetComment();
//document.getElementById("textComment") = text;
});
}
})(window, undefined);
For example, in this code, how can I assign a value to a control with ID textComment after I get comments
Thank you for description.
Unfortunately, we don’t have such methods at the moment. We added a suggestion to internal tracksystem (internal number - 58063). We have started working on it.
Sorry for inconvenience.
Hey! Has this issue been resolved yet?
Hello @Rinzler
We are still working on the mentioned method at the moment. I will update this thread when we have something to share.
Thanks @Alexandre!
Found workaround - use localStorage))
We are glad that you found workaround solution. If you want, you can post it here for other users.
Hello! Are there any updates on this?
Hello @arc-grigorenko
We are still looking into it. I will immediately update this thread, when we have any news.
Hello @shangshandalaohu
Please check out this sample:
window.Asc.plugin.callCommand(function () {
var oWorksheet = Api.GetActiveSheet();
var ActiveCell = oWorksheet.ActiveCell;
var comment = ActiveCell.GetComment();
return comment.GetText();
}, false, false, function (text) {
console.log(text)
});
the callCommand can return simple data (lines, numbers) to a plugin now. Please let us know if this is what you are looking for. If I misunderstood the scenario, please provide us with details.
workaround (Maybe it’s not relevant anymore)
window.Asc.plugin.callCommand(function() {
let oWorksheet = Api.GetActiveSheet();
let ActiveCell = oWorksheet.ActiveCell;
let comment = ActiveCell.GetComment();
localStorage.setItem('pluginTest', comment);
}, false, false, function() {
console.log(localStorage.getItem('pluginTest');
});
localStorage.removeItem('pluginTest');
use JSON if need
2 Likes
Thank you for your sharing! I hope it will be useful in such scenarios.