We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get Icon of cell with FormatCondition

ConditionalFormattingCollection conditionalFormattings = worksheet.getConditionalFormattings();
for (int i = 0; i < conditionalFormattings.getCount(); i++) {
FormatConditionCollection formatConditionCollection = conditionalFormattings.get(i);
for (int j = 0; j < formatConditionCollection.getCount(); j++) {
FormatCondition formatCondition = formatConditionCollection.get(j);
switch (formatCondition.getType()) {
case FormatConditionType.ICON_SET:
IconSet iconSet = formatCondition.getIconSet();
}




But how can I get which Icon should be use in cell E4~E14?

Hi,


Thank you for contacting Aspose support.

If you wish to retrieve the image data for the icon used on particular cell as a result of conditional formatting rule then you may use the following piece of code.

Java

Workbook book = new Workbook(dir + “cond3.xlsx”);
Worksheet worksheet = book.getWorksheets().get(0);
for(int i = 3; i < 14; i++)
{
Cell cell = worksheet.getCells().get(i, CellsHelper.columnNameToIndex(“E”));
ConditionalFormattingResult result = cell.getConditionalFormattingResult();
ConditionalFormattingIcon icon = result.getConditionalFormattingIcon();
FileOutputStream fos = new FileOutputStream(dir + cell.getName() + “.png”);
fos.write(icon.getImageData());
fos.close();
}

Hi again,


If you wish to retrieve which type of arrow is being used on particular cell as a result of conditional formatting rule then you have to develop a mapping mechanism on your own because Aspose.Cells APIs do not provide an enumeration for this purpose. Please check the following piece of code for elaboration.

Java

Workbook book = new Workbook(dir + “cond3.xlsx”);
Worksheet worksheet = book.getWorksheets().get(0);
for(int i = 3; i < 14; i++)
{
Cell cell = worksheet.getCells().get(i, CellsHelper.columnNameToIndex(“E”));
ConditionalFormattingResult result = cell.getConditionalFormattingResult();
ConditionalFormattingIcon icon = result.getConditionalFormattingIcon();
int style = icon.getIndex();

String styleName;
switch (style) {
case 0: styleName = “Up Arrow”;
break;
case 1: styleName = “Right Arrow”;
break;
case 2: styleName = “Down Arrow”;
break;
default: styleName = “Invalid”;
break;
}
System.out.println(styleName);
}