Fetch the correct conditional formatting color of the cell via Office Script in Excel 365

Shubham Saurabh 0 Reputation points
2023-08-15T20:27:37.98+00:00

"

function main(workbook: ExcelScript.Workbook) {
    // Your code here
    //let selectedRange = workbook.getSelectedRange();
    //console.log(selectedRange.getAddress());
    //console.log(selectedRange.getConditionalFormat().getCustom().getFormat())
    //let positive = selectedRange.getConditionalFormat().getType()
    //console.log(positive)

    var sheet = workbook.getActiveWorksheet();
    //var cell = sheet.getRange("G2");
    var cell = sheet.getRange("H2");
    var conditionalFormats = cell.getConditionalFormats();
    

    //console.log(cell.getConditionalFormat().getCustom().getFormat().getFill().getColor())

    for (var i = 0; i < conditionalFormats.length; i++) {
        var conditionalFormat = conditionalFormats[i];
        var fill = conditionalFormat.getCustom().getFormat().getFill()
        //var fill = conditionalFormat.getCustom().getFormat().
        console.log("Color: " + fill.getColor())
        //console.log("Color: " + fill.getColor().fontcolor())
    }
}

"

Based on above script I am getting this out put however I just want the exact color of the conditional formatting in the cell.

User's image

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,058 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,874 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.