i want to compare two colums in and excel and write the result in the 3rd column.
output file should be like this
This is wat i have done till now
import java.util.List; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import java.io.FileInputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.Pattern;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Test {
/**
* @param args
*/ //variable declarations
String element;
static String storedElement[][]=null;
static String Element[][]=null;
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException {
// TODO Auto-generated method stub
FileInputStream fs=new FileInputStream("file location(.xls)");
Workbook wb=Workbook.getWorkbook(fs);
Sheet sh=wb.getSheet(0);
Workbook workbook = Workbook.getWorkbook(new File("file location(.xls)"));
WritableWorkbook ww= Workbook.createWorkbook(new File("file location(.xls)RENAME THE FILE here "), workbook);
WritableSheet ws=ww.getSheet(0);
Label label;
//retrieving values from excel and storing in array
storedElement = new String[sh.getColumns()][sh.getRows()];
Element = new String[sh.getColumns()][sh.getRows()];
//for (int j = 0; j <sh.getColumns(); j++)
//{
int j=0; //column #0
int q=1; //column #1
//StringBuilder sb = new StringBuilder();
for (int i = 2; i < sh.getRows(); i++) //loop to run all rows
{
Cell cell = sh.getCell(j, i);
Cell cell1=sh.getCell(q,i);
storedElement[j][i] = cell.getContents();
Element[q][i]=cell1.getContents();
String elem = storedElement[j][i];
System.out.println(elem);
String elem1= Element[q][i];
System.out.println(elem1);
String[] ob1=elem1.split("\n");
System.out.println(ob1[i]);
String[] ob = elem.split("\n");
System.out.println(ob[i]);
//for(int k=0;k<ob.length;k++){
int k=0;
while (k<ob.length){
if (ob[k]==ob1[k]){
System.out.println(ob[k]);
System.out.println(ob1[k]);
label=new Label(2,i,"Valid");
}
else {
System.out.println(ob[k]);
System.out.println(ob1[k]);
label=new Label(2,i,"InValid");
}
k++;
//add new line ??
ws.addCell(label);
ww.write();
ww.close();
workbook.close();
}
}
}
}
i want to compare two columns in and excel and write the result in the 3rd column. here the cell contains two words where i need to write status for two words please help me in doing it