Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. @SuppressWarnings("unchecked")
  2. public static void readData() throws Exception {
  3.  
  4. String filename = "C://Users//ke00348200//Desktop//Cleaning_test/AACR (orals) 1st Itn INPUT.xlsx";
  5. FileInputStream fis = null;
  6. fis = new FileInputStream(filename);
  7.  
  8. XSSFWorkbook workbook = new XSSFWorkbook(fis);
  9.  
  10. XSSFSheet sheet = workbook.getSheetAt(0);
  11. //we will search for column index containing string "Your Column Name" in the row 0 (which is first row of a worksheet
  12. String columnWanted = "Title";
  13. Integer columnNo = null;
  14. //output all not null values to the list
  15. List<Cell> cells = new ArrayList<Cell>();
  16.  
  17. Row firstRow = sheet.getRow(0);
  18.  
  19. for(Cell cell:firstRow){
  20. if (cell.getStringCellValue().equals(columnWanted))
  21. {
  22. columnNo = cell.getColumnIndex();
  23. }
  24. }
  25. if (columnNo != null){
  26. for (Row row : sheet) {
  27. Cell c = row.getCell(columnNo);
  28. if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
  29. // Nothing in the cell in this row, skip it
  30. } else {
  31. System.out.println("data>>"+c.getStringCellValue());
  32. cells.add(c);
  33. }
  34. }
  35. }else{
  36. System.out.println("could not find column " + columnWanted + " in first row of " + fis.toString());
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement