For bug reports, provide the steps to reproduce and if possible a minimal demo of the problem.
OS version: 10
App version: 8.0.1.31
Goal: Get fill color of specific cell to compare to other cells within another range.
Tried: Code example Use an ONLYOFFICE macro to calculate the sum of the highlighted cells | ONLYOFFICE Blog.
Snippet from above example that emits error in this topic’s title:
const oWorksheet = Api.GetActiveSheet();
const range1 = oWorksheet.GetRange(“C3”); // Set your range for the color reference
const targetedColor = range1.GetFillColor();
const cellColorCode = targetedColor.GetRGB(); // < - GetRGB is not a function
Perhaps source had outpaced docs. How can I achieve my goal?
If a cell has no fill color, GetFillColor()
returns No Fill
, and No Fill
actually does not have a GetRGB()
function. Hence the error.
To avoid this error, make sure that all relevant cells (reference cell and relevant target cells) actually have a fill color. Change const cellColorCode
to let cellColorCode
. Then use the if
statement to make sure thattargetedColor
is not No Fill
, like showed in the code example.
Check the example you mentioned again, I found the code there really helpful to understand what’s going on.
Thanks @carsten87 for your reply.
Allow me to restate the goal. Disregard the snippets in the OP. I want the documented example macro to work on win 10 with 8.0.1.32 desktop editors.
What edits to the documented example are required?
The example at Use an ONLYOFFICE macro to calculate the sum of the highlighted cells | ONLYOFFICE Blog, fails for me.
The console displays “TypeError: cellColor.GetRGB is not a function
at eval (eval at (eval at (sdk-all-min.js:1:1)), :28:36) …”
Hello @Dario_BCS
Please note that you are using quite outdated version of Desktop Editors. I recommend updating and checking the situation again.
What edits to the documented example are required?
I’m pretty sure it’s a mistake in your code, not the example.
In addition to the recommendation by @Constantine, please copy-paste the entire macro code example from the bottom section of the tutorial (right above the video) and see if it works.
Using OO 8.2.2.22 on manjaro linux, the macro code from the tutorial works just fine, while the snippet you posted throws the error you are experiencing (for the reason I explained above).
1 Like
Thank you @Constantine for the 8.0 ‘old’ version warning. The example GetRGB function works without errors with win 10 desktop spreadsheet editor 8.2.2.22.
I am pleased to see auto updates in 8.2; I was spoiled by other apps prompting for updates.
@carsten87 thanks for taking a swing at this for me. Firstly, your suggestion that a worksheet should be formatted so that the function would not raise an error needs a bit more thought. Secondly, I restated the goal in post #3. I guess I could have clarified that this post was raised because the pasted example code was throwing the error, not my cobbled snippet.
Happy coding everyone
Glad to know that the situation has been sorted out.