import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import com.adeptia.indigo.logging.Logger; import java.util.Iterator; //String excelFilePath = "C:/Program Files/AdeptiaSuite/AdeptiaSuite-6.5/AdeptiaServer/ServerKernel/Solutions/TestColoring.xls";//Specify location of file int statusColumn = -1; try { //FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); Workbook workbook = WorkbookFactory.create(inputStream); Sheet sheet = workbook.getSheetAt(0); Iterator rows = sheet.rowIterator(); service.getLogger().info("-----checkstatusColumn column number:"+inputStream); while (rows.hasNext()) { Row row = rows.next(); System.out.println("The Row Number is " + row.getRowNum()); // Iterate over each cell in the row and print out the cell's content Iterator cells = row.cellIterator(); while (cells.hasNext()) { Cell cell = cells.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: System.out.println(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: System.out.println(cell.getStringCellValue()); String text = cell.getStringCellValue(); if ("Status".equals(text)) { statusColumn = cell.getColumnIndex(); } if(cell.getColumnIndex() == 1){ //Specify the column index for "Status" column if(cell.getStringCellValue().equals("fail")){ CellStyle style = workbook.createCellStyle(); //service.getLogger().info("-----fail"); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); cell.setCellStyle(style); } } break; default: System.out.println("unsuported sell type"); break; } } } inputStream.close(); FileOutputStream fos = new FileOutputStream(new File("C:/Program Files/AdeptiaSuite/AdeptiaSuite-6.5/AdeptiaServer/ServerKernel/Solutions/TestColoring.xls"));//Specify location of file workbook.write(fos); workbook.close(); fos.close(); fos.flush(); }catch(Exception e) { System.out.println(e.getMessage()); }