public void WriteToExcel(String UserID) {
XSSFWorkbook wb = new XSSFWorkbook();
String Id = "";
String Fn = "";
String Ln = "";
String Org = "";
String Status = "";
String Cdate="";
try {
System.out.println("Creating File...");
FileOutputStream finalOutput = new FileOutputStream(
"D:/Newfolder/AD.xls");
int rowCount = 0;
XSSFRow outputRow = null;
XSSFCell cell;
XSSFSheet reportSheet = wb.createSheet("User Details");
System.out.println("Writing Records...");
XSSFRow headerRow = reportSheet.createRow(rowCount++);
cell = headerRow.createCell(0, Cell.CELL_TYPE_STRING);
cell.setCellValue("UserId");
cell = headerRow.createCell(1, Cell.CELL_TYPE_STRING);
cell.setCellValue("First Name");
cell = headerRow.createCell(2, Cell.CELL_TYPE_STRING);
cell.setCellValue("Last Name");
cell = headerRow.createCell(3, Cell.CELL_TYPE_STRING);
cell.setCellValue("Organization");
cell = headerRow.createCell(4, Cell.CELL_TYPE_STRING);
cell.setCellValue("Status");
cell = headerRow.createCell(5, Cell.CELL_TYPE_STRING);
cell.setCellValue("Created Date");
ArrayList getuserMap=getDetails(UserID);
Iterator<HashMap> listval = getuserMap.iterator();
while (listval.hasNext()) {
HashMap values = listval.next();
System.out.println("Keys--->" + values);
Id=(String) values.get("Users.User ID");
Fn=(String) values.get("Users.First Name");
Ln=(String) values.get("Users.Last Name");
Org=(String) values.get("Users.Xellerate Type");
Status=(String) values.get("Users.Status");
Cdate=(String) values.get("Users.Creation Date");
outputRow = reportSheet.createRow(rowCount++);
cell = outputRow.createCell(0, Cell.CELL_TYPE_STRING);
cell.setCellValue(Id);
cell = outputRow.createCell(1, Cell.CELL_TYPE_STRING);
cell.setCellValue(Fn);
cell = outputRow.createCell(2, Cell.CELL_TYPE_STRING);
cell.setCellValue(Ln);
cell = outputRow.createCell(3, Cell.CELL_TYPE_STRING);
cell.setCellValue(Org);
cell = outputRow.createCell(4, Cell.CELL_TYPE_STRING);
cell.setCellValue(Status);
cell = outputRow.createCell(5, Cell.CELL_TYPE_STRING);
cell.setCellValue(Cdate);
}
wb.write(finalOutput);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ArrayList getDetails(String userID) {
System.out.println("Getting the details of the user"+userID);
ArrayList<HashMap> list=new ArrayList<HashMap>();
String Fn = "";
String Ln = "";
String Org = "";
String Status = "";
String Cdate="";
HashMap userMap = new HashMap();
HashMap resultMap;
try {
userMap.put("Users.User ID", userID);
tcResultSet moResultSet = moUserUtility.findUsers(userMap);
for (int i = 0; i < moResultSet.getRowCount(); i++) {
moResultSet.goToRow(i);
userID = moResultSet.getStringValue("Users.User ID");
Fn = moResultSet.getStringValue("Users.First Name");
Ln = moResultSet.getStringValue("Users.Last Name");
Org = moResultSet.getStringValue("Users.Xellerate Type");
Status = moResultSet.getStringValue("Users.Status");
Cdate = moResultSet.getStringValue("Users.Creation Date");
resultMap = new HashMap();
resultMap.put("Users.User ID", userID);
resultMap.put("Users.First Name", Fn);
resultMap.put("Users.Last Name", Ln);
resultMap.put("Users.Xellerate Type", Org);
resultMap.put("Users.Status", Status);
resultMap.put("Users.Creation Date", Cdate);
list.add(resultMap);
//System.out.println(list);
}
System.out.println("Returning HashMap");
} catch (Exception e) {
e.printStackTrace();
}
return list;
}