on 02-27-2014 11:32 AM
I am reading LDAP for a user and fetching in a Linked list. Then finally I have to write the users details to the excel sheet. Can anybody suggest how do I do it? I have written below code for it:
private void exporttoExcel(Map<String, Object> jnjUserMap) throws IOException, HPSFException {
// TODO Auto-generated method stub
//writing userdetails to excelsheet
HSSFWorkbook idms_users= new HSSFWorkbook();
String sheetName = "Pharma-MDM-25th Sept 2013";
HSSFSheet mdm_lastLoginDate_Sheet =idms_users.createSheet(sheetName);
HSSFRow row = mdm_lastLoginDate_Sheet.createRow((short)0);
File outputFile = new File("C:/samplexmls/sample.xls");
ArrayList headers = new ArrayList();
int rowIndex = 0;
short cellIndex = 0;
// ArrayList data, File outputFile
//header
headers.add("UserName");
headers.add("Last Login Date");
headers.add("Repository Name");
headers.add("Days from current date");
HSSFRow hssfHeader = mdm_lastLoginDate_Sheet.createRow(rowIndex);
HSSFCellStyle hssFCellStyle = idms_users.createCellStyle();
hssFCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
for(Iterator cells=headers.iterator();cells.hasNext();)
{
HSSFCell hssfCell = hssfHeader.createCell(cellIndex++);
hssfCell.setCellStyle(hssFCellStyle);
hssfCell.setCellValue((String) cells.next());
}
System.out.println("Hiiiiiiiii");
//Iterate over data and write to sheet
Set<String> keyset = jnjUserMap.keySet();
rowIndex= 0;
for (String key : keyset)
{
row = mdm_lastLoginDate_Sheet.createRow(rowIndex++);
JNJUser [] objArr = (JNJUser[]) jnjUserMap.get(key);
cellIndex = 1;
for (Object obj : objArr)
{
HSSFCell hssfCell = hssfHeader.createCell(cellIndex++);
if(obj instanceof String)
hssfCell.setCellValue((String)obj);
else if(obj instanceof Integer)
hssfCell.setCellValue((Integer)obj);
}
}
idms_users.setSheetName(0, sheetName, HSSFWorkbook.ENCODING_COMPRESSED_UNICODE);
FileOutputStream fileOut = new FileOutputStream("c:/temp/pg_products1.xls");
idms_users.write(fileOut);
fileOut.close();
System.out.println("file Created");
}
But I am getting below error at the line number 44. getting below error:
Exception in thread "main" java.lang.ClassCastException: com.jnj.JNJUser cannot be cast to [Lcom.jnj.JNJUser;
at com.jnj.JNJLDAPManager1.exporttoExcel(JNJLDAPManager1.java:257)
at com.jnj.JNJLDAPManager1.getJNJMembers(JNJLDAPManager1.java:200)
at com.jnj.JNJLDAPManager1.main(JNJLDAPManager1.java:332)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
buddy, just syntax problem, you cannot figure out?
check what you have put into map
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.