import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Vector;
import java.lang.String;
import javax.swing.JOptionPane;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelXLSX {
public static Object TestType;
public static Object TargetEnvironment;
public static Object TargetSystem;
public static Object TargetRegion;
public static Object TargetKeyword;
public static Object name1 = "Shakedown";
private Vector DataExcel = new Vector();
public ExcelXLSX() {
String FileName = "C:\\Users\\u304081\\Desktop\\Java\\FrameWork.xlsx ";
DataExcel = ReadExcel(FileName);
displayDataExcelXLSX(DataExcel);
}
public static Vector ReadExcel(String fileName) {
Vector vectorData = new Vector();
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
XSSFWorkbook ObjWorkBook = new XSSFWorkbook(fileInputStream);
// Read data at sheet 0
XSSFSheet ObjSheet = ObjWorkBook.getSheetAt(0);
Iterator rowIteration = ObjSheet.rowIterator();
// Looping every row at sheet 0
while (rowIteration.hasNext()) {
XSSFRow Row = (XSSFRow) rowIteration.next();
Iterator cellIteration = Row.cellIterator();
Vector CellEachRowData = new Vector();
// Looping every cell in each row at sheet 0
while (cellIteration.hasNext()) {
XSSFCell Cell = (XSSFCell) cellIteration.next();
CellEachRowData.addElement(Cell);
}
vectorData.addElement(CellEachRowData);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return vectorData;
}
public static void displayDataExcelXLSX(Vector vectorData) {
// Looping every row data in vector
Vector TestType1 = (Vector) vectorData.get(1);
Vector TargetEnvironment1 = (Vector) vectorData.get(2);
Vector TargetSystem1 = (Vector) vectorData.get(3);
Vector TargetRegion1 = (Vector) vectorData.get(4);
Vector TargetKeyword1 = (Vector) vectorData.get(5);
// looping every cell in each row
//System.out.print(TestType.get(1).toString()+" \t");
//JOptionPane.showMessageDialog(null,TestType1.get(1 ));
TestType = TestType1.get(1);
//TestType.toString();
//String Testtype2 = (String) TestType;
System.out.println("TestTYpe " + TestType);
TargetEnvironment = TargetEnvironment1.get(1);
System.out.println("TargetEnvironment " + TargetEnvironment);
TargetSystem = TargetSystem1.get(1);
System.out.println("TargetSystem " + TargetSystem);
TargetRegion = TargetRegion1.get(1);
System.out.println("TargetRegion " + TargetRegion);
TargetKeyword = TargetKeyword1.get(1);
System.out.println("TargetKeyword " + TargetKeyword);
//Script to display the options selected in Framework
// switch (RValue) {
// case 0 :
// case 1 : break;
// }
}
public static void main(String[] args) {
new ExcelXLSX();
String StrMsg="You have choosen " + "\t" + TestType + "-" + TargetEnvironment + "-" + TargetSystem + "-" + TargetRegion + "\t" + "Do you want to continue..";
int RValue=JOptionPane.showConfirmDialog(null, StrMsg);
System.out.println("RValue: "+RValue);
switch (RValue) {
//For selecting Yes Button
case 0 :
System.out.println("Yes is Selected");
System.out.println("Test type_sheet:" + TestType);
TestType.toString();
name1.toString();
//Object name2 = name1;
System.out.println("Test type_comparison:" + name1);
Boolean y = TestType.equals(name1);
System.out.println("Y:" + y);
if (TestType.equals(name1)) { //I am comparing two objects here.But it returning False here.
System.out.println("Testtype is SD/Reg/Keyword");
}
else {
System.out.println("Not SD/Reg/Keyboard");
} // Here is my problem
break;
// For selecting NO Button
case 1 :
System.out.println("NO is selected");
break;
}
}
}