How to sortOn cell color with ExcelScript?

Wolfeius 1 Reputation point
2022-03-21T16:28:38.177+00:00

I am trying to sort in descending order the cells with a 'rose' background, as you can do in the 'filter' or 'custom sort' but with ExcelScript for web:

range.getSort().apply([ {
    ascending: false,
    key: 5,
    sortOn: ExcelScript.SortOn.cellColor,
    subField: "Rose"
 }]);

But it does not work. I have tried to record a macro with either sorting cell color or font but the macro does not record the SortOn, instead it just shows:

selectedSheet.getRange("A8:K50").getSort().apply([{key: 0, ascending: true}], false, true);

Is there any way to sortOn cell color with ExcelScripts?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
872 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,508 questions
{count} votes