Aspose Cells : How to extract the conditionalFormats details

We would like to know how to extract each of these details. specially the iconCriteria, minType, minValue, gradient, etc


3
2
5
59
1
#FF0000
normal normal 10pt Arial
0
F3<0
2
12
2
6
59
1
5
null
7
null
false
rgba(79,118,153,1)
true
13
2
5
59
1
2
true
4
33
true
4
67
3

Hi,

Thanks for your posting and using Aspose.Cells.

You can read the settings of all conditional formatting objects from Worksheet.getConditionalFormattings().

Please see the following sample code that reads all of your 3 conditional formatting objects one by one and extract their settings. I have also shown the console output of this code for your reference.

Java


Workbook workbook = new Workbook("__Trends_1_1_1_18_1_SingleCF.xlsx");


Worksheet worksheet = workbook.getWorksheets().get(0);


//Reading your first Conditional Formatting which is DataBar

FormatConditionCollection fcc = worksheet.getConditionalFormattings().get(0);


FormatCondition fc = fcc.get(0);


System.out.println(fc.getType() == FormatConditionType.DATA_BAR);

System.out.println(fc.getDataBar().getBarFillType() == DataBarFillType.SOLID);

System.out.println(fc.getDataBar().getColor());

System.out.println(fc.getDataBar().getMaxCfvo().getType() == FormatConditionValueType.AUTOMATIC_MAX);

System.out.println(fc.getDataBar().getMinCfvo().getType() == FormatConditionValueType.AUTOMATIC_MIN);


System.out.println(“Range: " + fcc.getCellArea(0));


System.out.println(”----------------------------------\r\n");


//Reading your second Conditional Formatting which is Expression

fcc = worksheet.getConditionalFormattings().get(1);

fc = fcc.get(0);


System.out.println(fc.getType() == FormatConditionType.EXPRESSION);

System.out.println("Formula1: " + fc.getFormula1());

System.out.println("Style Font Name: " + fc.getStyle().getFont().getName());

System.out.println(“Style Font Color: " + fc.getStyle().getFont().getColor());


System.out.println(“Range: " + fcc.getCellArea(0));


System.out.println(”----------------------------------\r\n”);


//Reading your third Conditional Formatting which is IconSet

fcc = worksheet.getConditionalFormattings().get(2);

fc = fcc.get(0);


System.out.println(fc.getType() == FormatConditionType.ICON_SET);

System.out.println(fc.getIconSet().getType() == IconSetType.CUSTOM_SET);


//-----Read 3rd icon which is 3rd icon of Triangles3

System.out.println(fc.getIconSet().getCfIcons().get(2).getType() == IconSetType.TRIANGLES_3);

System.out.println(fc.getIconSet().getCfIcons().get(2).getIndex());

System.out.println(fc.getIconSet().getCfIcons().get(2).getImageData());


//----Read 3rd value

System.out.println(fc.getIconSet().getCfvos().get(2).getType() == FormatConditionValueType.NUMBER);

System.out.println(fc.getIconSet().getCfvos().get(2).getValue());

System.out.println("Is Greater Than Equal: " + fc.getIconSet().getCfvos().get(2).isGTE());


System.out.println("Range: " + fcc.getCellArea(0));

Console Output:
true
true
com.aspose.cells.Color@4f7699
true
true
Range: Aspose.Cells.CellArea(G3:G61)[2,6,60,6]
----------------------------------

true
Formula1: =F3<0
Style Font Name: Arial
Style Font Color: com.aspose.cells.Color@ff0000
Range: Aspose.Cells.CellArea(F3:F61)[2,5,60,5]
----------------------------------

true
true
true
2
[B@110003
true
1
Is Greater Than Equal: true
Range: Aspose.Cells.CellArea(F3:F61)[2,5,60,5]

Hi,

Thanks for using Aspose.Cells.

Here is a .NET code for your reference. Please note, it will be easier for you to look into APIs in .NET environment, then you can port your code to Java easily.

C#


Workbook workbook = new Workbook("__Trends_1_1_1_18_1_SingleCF.xlsx");


Worksheet worksheet = workbook.Worksheets[0];


//Reading your first Conditional Formatting which is DataBar

FormatConditionCollection fcc = worksheet.ConditionalFormattings[0];


FormatCondition fc = fcc[0];


Console.WriteLine(fc.Type == FormatConditionType.DataBar);

Console.WriteLine(fc.DataBar.BarFillType == DataBarFillType.Solid);

Console.WriteLine(fc.DataBar.Color);

Console.WriteLine(fc.DataBar.MaxCfvo.Type == FormatConditionValueType.AutomaticMax);

Console.WriteLine(fc.DataBar.MinCfvo.Type == FormatConditionValueType.AutomaticMin);


Console.WriteLine(“Range: " + fcc.GetCellArea(0));


Console.WriteLine(”----------------------------------\r\n");


//Reading your second Conditional Formatting which is Expression

fcc = worksheet.ConditionalFormattings[1];

fc = fcc[0];


Console.WriteLine(fc.Type == FormatConditionType.Expression);

Console.WriteLine("Formula1: " + fc.Formula1);

Console.WriteLine("Style Font Name: " + fc.Style.Font.Name);

Console.WriteLine(“Style Font Color: " + fc.Style.Font.Color);


Console.WriteLine(“Range: " + fcc.GetCellArea(0));


Console.WriteLine(”----------------------------------\r\n”);


//Reading your third Conditional Formatting which is IconSet

fcc = worksheet.ConditionalFormattings[2];

fc = fcc[0];


Console.WriteLine(fc.Type == FormatConditionType.IconSet);

Console.WriteLine(fc.IconSet.Type == IconSetType.CustomSet);


//-----Read 3rd icon which is 3rd icon of Triangles3

Console.WriteLine(fc.IconSet.CfIcons[2].Type == IconSetType.Triangles3);

Console.WriteLine(fc.IconSet.CfIcons[2].Index);

Console.WriteLine(fc.IconSet.CfIcons[2].ImageData);


//----Read 3rd value

Console.WriteLine(fc.IconSet.Cfvos[2].Type == FormatConditionValueType.Number);

Console.WriteLine(fc.IconSet.Cfvos[2].Value);

Console.WriteLine("Is Greater Than Equal: " + fc.IconSet.Cfvos[2].IsGTE);


Console.WriteLine("Range: " + fcc.GetCellArea(0));