Free Support Forum - aspose.com

Reading Icon from Custom Icon Criteria Applied

How do i read the Icon & its IconSet Type if custom Icon Style Conditional Formatting is applied?

@harshaghanta,

See the following sample code segments and write your own code to read conditional formattings results and attributes:
e.g
Sample code:

//Open a template Excel file
Workbook workbook = new Workbook(@“e:\test2\Testoutput.xlsx”);

        //Get the first worksheet in the workbook
        Worksheet sheet = workbook.Worksheets[0];

        //Get the A1 cell
        Cell cell = sheet.Cells["A1"];

        //Get the conditional formatting result object
        ConditionalFormattingResult cfr = cell.GetConditionalFormattingResult();
        //Get the icon set
        ConditionalFormattingIcon icon = cfr.ConditionalFormattingIcon;

        DataBar databar = cfr.ConditionalFormattingDataBar;
       
         //Create the image file based on the icon's image data
        File.WriteAllBytes("e:\\test2\\ff2icons.jpg", icon.ImageData);

//Instantiate Workbook object
Workbook workbook = new Workbook(“e:\test2\Book1.xlsx”);
Worksheet sheet = workbook.Worksheets[0];

  	ConditionalFormattingCollection cfs = sheet.ConditionalFormattings;

FormatConditionCollection fcs = cfs[0];
//Get first format condition.
FormatCondition fc = fcs[0];
//Get the Formula1
string f1 = fc.Formula1;
MessageBox.Show(f1.ToString());
//Get the Formula2
string f2 = fc.Formula2;
MessageBox.Show(f2.ToString());
//Get the operator type.
object op = fc.Operator;
MessageBox.Show(op.ToString());
//Get the format condition type.
object t = fc.Type;
MessageBox.Show(t.ToString());

Hope, this helps a bit.