TypeScript Code

link - learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-conditional-formatting


Excel.run ( function (context) { 
   var _sheet = context.workbook.worksheets.getActiveWorksheet();
   var _range = _sheet.getRange("A1:E10");
   var _conditionalFormat = _range.conditionalFormats.add(Excel.ConditionalFormatType.custom);

   _conditionalFormat.custom.format.fill.color = "yellow";
   _conditionalFormat.custom.rule.formula = "If((AND($E1>100,$E1<300)),TRUE)";

   //alternative syntax
   _conditionalFormat.custom.rule.formula = {formula1: "=100", formula2="=300", operator:"Between"};
}

This script applies green fill conditional formatting to the top 10% of values in the used range.

function main(workbook: ExcelScript.Workbook) { 
  let selectedSheet = workbook.getActiveWorksheet();
  let range = selectedSheet.getUsedRange();

  let conditionalFormat = range.addConditionalFormat(ExcelScript.ConditionalFormatType.topBottom)
  conditionalFormat.getTopBottom().getFormat().getFill().setColor("green");
  conditionalFormat.getTopBottom().setRule({
    rank: 10,
    type: ExcelScript.ConditionalTopBottomCriterionType.topPercent
  });
}

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext