Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. rollno user_name user_email_id class_type request_status
  2. --------------------------------------------------------------
  3. CM5C9CBJJP Isaac James isaac.james@gmail.com 1 Accepted
  4. E6U13NFHGG Sean Allan sean.allan@gmail.com 1 Deactivated
  5. SNAJHHVV8Q Dylan Avery dylan.avery@gmail.com 1 Accepted
  6. RNN71FJ5QS Max Fisher max.fisher@gmail.com 1 Rejected
  7. 6NKKI603BM Owen Grant owen.grant@gmail.com 1 Deactivated
  8.  
  9. public class StoreStudents {
  10.  
  11. public static void main(String[] args) throws IOException {
  12. //HashMap Declaration.
  13. HashMap<String, List<String>> map = new HashMap<>();
  14. List<String> studentData = new ArrayList<>();
  15. // Read Excel FIle Sheet
  16. File excelFile = new File("user_details.xlsx");
  17. FileInputStream fis = new FileInputStream(excelFile);
  18. XSSFWorkbook workbook = new XSSFWorkbook(fis);
  19. XSSFSheet sheet = workbook.getSheetAt(0);
  20. Iterator<Row> rowIt = sheet.iterator();
  21. String k1 = "default";
  22. int count = 0,objCount = 0;
  23. while(rowIt.hasNext()) {
  24. count = count + 1;
  25. Row row = rowIt.next();
  26. // iterate on cells for the current row
  27. Iterator<Cell> cellIterator = row.cellIterator();
  28. if (row.getRowNum() != 0) {
  29. while (cellIterator.hasNext()) {
  30. Cell cell = cellIterator.next();
  31. //System.out.println(cell.getColumnIndex());
  32. if (cell.getColumnIndex() == 0) {
  33. k1 = cell.toString();
  34. System.out.println("1. key is " + k1);
  35. }
  36. else {
  37. studentData.add(cell.toString());
  38. //System.out.println(studentData);
  39. //System.out.print(cell.toString() + ";");
  40. }
  41. }
  42. }
  43. System.out.println("key is " + k1);
  44. map.put(k1, studentData);
  45. System.out.println(map);
  46. studentData.clear();
  47. System.out.println(map);
  48. objCount = objCount + 1;
  49. }
  50.  
  51. }
  52.  
  53. }
  54.  
  55. Output:
  56. key is default
  57. {default=[]}
  58. 1. key is CM5C9CBJJP
  59.  
  60.  
  61. key is CM5C9CBJJP
  62. {CM5C9CBJJP=[Isaac James, isaac.james@gmail.com, 1.0, Accepted], default=[Isaac James, isaac.james@gmail.com, 1.0, Accepted]}
  63. 1. key is E6U13NFHGG
  64.  
  65.  
  66. key is E6U13NFHGG
  67. {CM5C9CBJJP=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated], default=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated], E6U13NFHGG=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated]}
  68. 1. key is SNAJHHVV8Q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement