I am trying to build a web-addin for Excel using OfficeJS.
I've added Icons to a range of cells using the following code.
async function addIcon() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const range = sheet.getRange("A1:E13");
const conditionalFormat = range.conditionalFormats
.add(Excel.ConditionalFormatType.iconSet);
const iconSetCF = conditionalFormat.iconSet;
iconSetCF.style = Excel.IconSet.threeFlags;
iconSetCF.showIconOnly=false;
iconSetCF.criteria = [
{
type: Excel.ConditionalFormatIconRuleType.number,
operator: Excel.ConditionalIconCriterionOperator.greaterThanOrEqual,
formula: ">0"
}
];
await context.sync();
});
}
The above code adds different icons for each of the cell values as shown in the images.
Can someone please answer the following questions?
Question1: Can we set the color of the Icon to a single color? I don't want to have different colors of the same Icon but want to set it to either Yellow or Red.
Question2: Can the Icon be applied to non-numeric cells?
As of now the icon is only applied to those cells with numeric values, and all the properties of the Excel.ConditionalFormatIconRuleType
are either number,Formula, percentile etc, which are useful only for numeric values.
I have tried the following code, but doesn't work.
iconSetCF.criteria = [
{
type: Excel.ConditionalFormatIconRuleType.Formula,
operator: Excel.ConditionalIconCriterionOperator.greaterThanOrEqual,
formula: "=ISTEXT(A1)"
}
];
Question3: Can we add custom icons instead of using the predefined iconSet?
Can I use a custom image as an Icon instead of using the office predefined icons?
I tried to use the Excel.ConditionalFormatType.custom
property but it can only apply colors or format the cells but cannot add any images inside the cells.
Kindly let me know your thoughts on the above questions? I couldn't find anything related to my above requirements in the OfficeJS's documentation.