Trying to write a marco on onlyoffice spreadsheet…
I want to be able to test a Cell FillColor (an idealy a FontColor) to compare it with a Ref and if equal do something.
Below a function trying to do it (You should be able to test it on your onlyoffice)
This function will write 3 Cell in Red, Green and No Color (As 3 ref)
Get the FillColor in variable
Then will Write 3 other cell with again color
I can set FillColor or Fontcolor by reding the adjacent cell but I am not able to compare the result with a ref…
My problme is with the test
if (cellToCheck == colorRed)
that does not works…
Thanks for help
(function()
{
const oWorksheet = Api.GetActiveSheet();
const colorRed = Api.CreateColorFromRGB(255, 0, 0)
const colorGreen = Api.CreateColorFromRGB(0, 255, 0)
oWorksheet.GetRangeByNumber(0, 0).SetValue("Red Ref");
oWorksheet.GetRangeByNumber(0, 0).SetFillColor(colorRed);
oWorksheet.GetRangeByNumber(1, 0).SetValue("Green Ref");
oWorksheet.GetRangeByNumber(1, 0).SetFillColor(colorGreen);
oWorksheet.GetRangeByNumber(2, 0).SetValue("No Ref");
oWorksheet.GetRangeByNumber(4, 0).SetValue("Test 1");
oWorksheet.GetRangeByNumber(4, 0).SetFillColor(colorRed);
oWorksheet.GetRangeByNumber(4, 1).SetValue("");
oWorksheet.GetRangeByNumber(4, 2).SetValue("");
oWorksheet.GetRangeByNumber(5, 0).SetValue("Test 2");
oWorksheet.GetRangeByNumber(5, 0).SetFillColor(colorGreen);
oWorksheet.GetRangeByNumber(5, 1).SetValue("");
oWorksheet.GetRangeByNumber(5, 2).SetValue("");
oWorksheet.GetRangeByNumber(6, 0).SetValue("Test 3");
oWorksheet.GetRangeByNumber(6, 1).SetValue("");
oWorksheet.GetRangeByNumber(6, 2).SetValue("");
var ref1 = oWorksheet.GetRangeByNumber(0, 0).GetFillColor();
var ref2 = oWorksheet.GetRangeByNumber(1, 0).GetFillColor();
var col = 0;
for (var ligne = 4; ligne < 7; ligne += 1) {
var cellToCheck = oWorksheet.GetRangeByNumber(ligne, col).GetFillColor();
if (cellToCheck !== "No Fill") {
oWorksheet.GetRangeByNumber(ligne, col + 1).SetValue("Check");
oWorksheet.GetRangeByNumber(ligne, col + 1).SetFontColor(cellToCheck);
}
else oWorksheet.GetRangeByNumber(ligne, col + 1).SetValue(cellToCheck);
}
for (ligne = 4; ligne < 7; ligne += 1) {
cellToCheck = oWorksheet.GetRangeByNumber(ligne, col).GetFillColor();
if (cellToCheck == colorRed) {
oWorksheet.GetRangeByNumber(ligne, col + 2).SetValue("Check");
oWorksheet.GetRangeByNumber(ligne, col + 2).SetFontColor(colorRed);
}
else oWorksheet.GetRangeByNumber(ligne, col + 2).SetValue(cellToCheck);
}
})();