@@ -155,19 +155,18 @@ public static Object[][] getDataHashTable(String ExcelPath, String SheetName, in
155155
156156 int rows = getRowCount ();
157157 int columns = getColumnCount ();
158- System .out .println ("Row: " + rows + " - Column: " + columns );
158+ // System.out.println("Row: " + rows + " - Column: " + columns);
159159 data = new Object [endRow - startRow ][1 ];
160160 Hashtable <String , String > table = null ;
161161 for (int rowNums = startRow ; rowNums < endRow ; rowNums ++) {
162- table = new Hashtable <String , String >();
162+ table = new Hashtable <>();
163163 for (int colNum = 0 ; colNum < columns ; colNum ++) {
164164 // data[rowNums-2][colNum] = excel.getCellData(sheetName, colNum, rowNums);
165165 table .put (getCellData (0 , colNum ), getCellData (rowNums , colNum ));
166166 data [rowNums - startRow ][0 ] = table ;
167167 }
168168 }
169169
170- System .out .println (data );
171170 } catch (FileNotFoundException e ) {
172171 e .printStackTrace ();
173172 } catch (IOException e ) {
@@ -350,16 +349,50 @@ public static int getColumnCount() {
350349 }
351350
352351 // Write data to excel sheet
353- public static void setCellData (String text , int rowNum , int colnum ) {
352+ public static void setCellData (String text , int rowNumber , int colNumber ) {
353+ try {
354+ row = sh .getRow (rowNumber );
355+ if (row == null ) {
356+ row = sh .createRow (rowNumber );
357+ }
358+ cell = row .getCell (colNumber );
359+
360+ if (cell == null ) {
361+ cell = row .createCell (colNumber );
362+ }
363+ cell .setCellValue (text );
364+
365+ XSSFCellStyle style = (XSSFCellStyle ) wb .createCellStyle ();
366+ if (text == "pass" || text == "passed" || text == "Pass" || text == "Passed" ) {
367+ style .setFillForegroundColor (IndexedColors .BRIGHT_GREEN .getIndex ());
368+ } else {
369+ style .setFillForegroundColor (IndexedColors .RED .getIndex ());
370+ }
371+ style .setFillPattern (FillPatternType .SOLID_FOREGROUND );
372+ style .setAlignment (HorizontalAlignment .CENTER );
373+ style .setVerticalAlignment (VerticalAlignment .CENTER );
374+
375+ cell .setCellStyle (style );
376+
377+ fileOut = new FileOutputStream (excelFilePath );
378+ wb .write (fileOut );
379+ fileOut .flush ();
380+ fileOut .close ();
381+ } catch (Exception e ) {
382+ System .out .println (e .getMessage ());
383+ }
384+ }
385+
386+ public static void setCellData (String text , int rowNum , String columnName ) {
354387 try {
355388 row = sh .getRow (rowNum );
356389 if (row == null ) {
357390 row = sh .createRow (rowNum );
358391 }
359- cell = row .getCell (colnum );
392+ cell = row .getCell (columns . get ( columnName ) );
360393
361394 if (cell == null ) {
362- cell = row .createCell (colnum );
395+ cell = row .createCell (columns . get ( columnName ) );
363396 }
364397 cell .setCellValue (text );
365398
0 commit comments