import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
*
* @author spice
*/
public class MSPDetails {
final static String[] header = {"S.No", "Phone No", "Name", "Address"};
public static void main(String[] args) throws IOException, BiffException {
int option;
Workbook wb = Workbook.getWorkbook(new File("sample.xls"));
Sheet sheet1 = wb.getSheet(0);
Sheet sheet2 = wb.getSheet(1);
ArrayList notDisturbList=new ArrayList();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do {
System.out.println("############# MENU ################");
System.out.println("Select the criteria: \n 1 for name \n 2 for address \n 3 for quit");
System.out.println("Enter your option :");
option = Integer.parseInt(br.readLine());
System.out.println("########################################");
switch (option) {
case 1:
System.out.println("Enter employee Name:");
findByCriteria(sheet1, sheet2, "name", br.readLine());
break;
case 2:
System.out.println("Enter employee Address:");
findByCriteria(sheet1, sheet2, "address", br.readLine());
break;
case 3:
System.out.println("Thank Q");
break;
default:
System.out.println("Invalid choise..Enter correct choise");
}
} while (option != 3);
}
static void findByCriteria(Sheet sheet1, Sheet sheet2, String criteria, String key) throws IOException {
boolean isFound = true;
Cell nameCell = sheet1.findCell(criteria);
int nameCellNo = nameCell.getColumn();
Cell[] listName = sheet1.getColumn(nameCellNo);
Cell phno = sheet2.findCell("phone no");
int phnoCellNo = phno.getColumn();
Cell[] dontDisturbList = sheet2.getColumn(phnoCellNo);
int phColNo = sheet1.findCell("phno").getColumn();
System.out.println("PHONE NUMBER");
for (int row = 1; row < listName.length; row++) {
Cell[] rowCell = sheet1.getRow(row);
if (criteria.equals("name") ? listName[row].getContents().equals(key) : listName[row].getContents().contains(key)) {
// System.out.println(rowCell[phColNo].getContents());
for (int ddRow = 1; ddRow < dontDisturbList.length; ddRow++) {
if (rowCell[phColNo].getContents().equals(dontDisturbList[ddRow].getContents())) {
isFound = false;
System.out.println("This is Dont Disturb Number");
}
}
}
if (isFound) {
System.out.println(header[phColNo] + ":" + rowCell[phColNo].getContents());
}
}
if (!isFound) {
System.out.println("Details with " + criteria + " " + key + " doesn't exist");
}
}
}
No comments:
Post a Comment