style.setFillForegroundColor(IndexedColors.GREEN.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
CellStyle style1 = wb.createCellStyle();
style1.setFillForegroundColor(IndexedColors.RED.getIndex());
style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
String str = strText.substring(0, (strText.indexOf("k")-1));
//sheet1.getRow(i).createCell(8).setCellValue(str);
String strx = strText1.substring(0, (strText1.indexOf("k")-1));
//sheet1.getRow(i).createCell(9).setCellValue(strx);
double d = Double.parseDouble(str);
double d1 = Double.parseDouble(strx);
if(d>d1) {
double no = (d1/d) + (d1 * (1/100));
if(d>(d1+no)) {
sheet1.getRow(i).createCell(7).setCellValue("Fail");
sheet1.getRow(i).createCell(7).setCellStyle(style1);
}
}
else {
sheet1.getRow(i).createCell(7).setCellValue("Pass");
sheet1.getRow(i).createCell(7).setCellStyle(style);
}
if(d1>d) {
double nos = (d/d1) + (d * (1/100));
if(d1>(d+nos)) {
sheet1.getRow(i).createCell(7).setCellValue("Fail");
sheet1.getRow(i).createCell(7).setCellStyle(style1);
}
}
else {
sheet1.getRow(i).createCell(7).setCellValue("Pass");
sheet1.getRow(i).createCell(7).setCellStyle(style);
}
When I execute this code my excel is updating only with the colors such as fail indicated by red and pass indicated by green.
Now my problem is I want to print the status (fail or pass) and color both in my cell, how should I do it?