Hi,
How to highlight the cell with highest value in a Column using Aspose code.
Please provide a code for this.
Can we do this without using Conditional Formatting. If yes, please provide a sample example.
Thanks,
Hi,
How to highlight the cell with highest value in a Column using Aspose code.
Please provide a code for this.
Can we do this without using Conditional Formatting. If yes, please provide a sample example.
Thanks,
Hi,
Please share same code for Java
Here you go:
e.g
Sample code:
Workbook workbook = new Workbook("e:\\test2\\bk_highestval.xlsx");
Worksheet worksheet = workbook.getWorksheets().get(0);
//Calculate the highest value in the first column A
//Get the last record/row index.
int maxrow = worksheet.getCells().getMaxDataRow() +1;
//Write the formula based on your desired range.
String formula1 = "=MAX(A1:A" + maxrow + ")" ;
Object result1 = worksheet.calculateFormula(formula1);
//Show the highest value
System.out.println(result1.toString());
//Find out the highest value in the column.
FindOptions opts = new FindOptions();
opts.setLookInType(LookInType.VALUES);
opts.setLookAtType(LookAtType.ENTIRE_CONTENT);
CellArea area = CellArea.createCellArea(0,0,maxrow,0);
opts.setRange(area);
//Search the cell that contains that value
Cell cell = worksheet.getCells().find(result1, null, opts);
//Set the background color of that cell to highlight it.
Style style = cell.getStyle();
style.setForegroundColor(Color.getYellow());
style.setPattern(BackgroundType.SOLID);
cell.setStyle(style);
//Save the excel file.
workbook.save("f:\\files\\outbk_highestval1.xlsx");
Hope, this helps a bit.