Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("unchecked")
- public static void readData() throws Exception {
- String filename = "C://Users//ke00348200//Desktop//Cleaning_test/AACR (orals) 1st Itn INPUT.xlsx";
- FileInputStream fis = null;
- fis = new FileInputStream(filename);
- XSSFWorkbook workbook = new XSSFWorkbook(fis);
- XSSFSheet sheet = workbook.getSheetAt(0);
- //we will search for column index containing string "Your Column Name" in the row 0 (which is first row of a worksheet
- String columnWanted = "Title";
- Integer columnNo = null;
- //output all not null values to the list
- List<Cell> cells = new ArrayList<Cell>();
- Row firstRow = sheet.getRow(0);
- for(Cell cell:firstRow){
- if (cell.getStringCellValue().equals(columnWanted))
- {
- columnNo = cell.getColumnIndex();
- }
- }
- if (columnNo != null){
- for (Row row : sheet) {
- Cell c = row.getCell(columnNo);
- if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
- // Nothing in the cell in this row, skip it
- } else {
- System.out.println("data>>"+c.getStringCellValue());
- cells.add(c);
- }
- }
- }else{
- System.out.println("could not find column " + columnWanted + " in first row of " + fis.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement