Wednesday 22 January 2014

Copying the One Excel sheet to another excel sheet and Update test cases staus using Java and JXL

import java.io.File;

import jxl.Workbook;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class SampleExcelStatus
{
      @BeforeTest
      public void setup() throws Exception
     
      {
           
      }

      @Test
      public static  void SecondExcelFile() throws Exception
      {   
        Workbook workbook = Workbook.getWorkbook(new File("E:/6409_TestCases_Checkout.xls"));
        WritableWorkbook copywb = Workbook.createWorkbook(new File("E:/6409_TestCases_CheckoutResultsSatya.xls"), workbook);
        WritableSheet sheet1=copywb.getSheet(0);
       
        for(int URowcount=12; URowcount<sheet1.getRows();URowcount++)
            {
                   Label label = new Label(10,URowcount-1,"Pass");
                   WritableCellFormat cfobj=new WritableCellFormat();
                    /*cfobj.setBackground(Colour.GREY_25_PERCENT);
                    cfobj.setAlignment(Alignment.LEFT);
                    cfobj.setOrientation(Orientation.HORIZONTAL);*/
                    cfobj.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);
                    label.setCellFormat(cfobj);
                   
                    sheet1.addCell(label);
            }
       
        copywb.write();
        copywb.close();
        workbook.close();
       
      }
     
            @AfterClass
            public void tearDown()
            {
            //    driver.close();
            }  
}