Get column names in Excel file using Apache POI

How to get column names in Excel file using Apache POI to make sure columns are ordered as expected.

+7
source share
3 answers

Or that:

cell.getSheet().getRow(0).getCell(currentcellIndex) .getRichStringCellValue().toString() 

Not sure if lines start at 0. Hope the logic works.

+5
source

There is a convenience method for this:

 CellReference.convertNumToColString(cell.getColumnIndex()); 

To get the full name:

 private static String getCellName(Cell cell) { return CellReference.convertNumToColString(cell.getColumnIndex()) + (cell.getRowIndex() + 1); } 
+16
source

Apache POI translating Excel column number to letter

  FileInputStream fis = new FileInputStream( new File("D:\\workspace\\Writesheet.xlsx")); @SuppressWarnings("resource") XSSFWorkbook workbook = new XSSFWorkbook(fis); XSSFSheet spreadsheet = workbook.getSheetAt(0); int lastcell=spreadsheet.getRow(0).getLastCellNum(); //Non empty Last cell Number or index return for(int i=0;i<=lastcell;i++) { try { System.out.println(CellReference.convertNumToColString(i)); }catch(Exception e) {} } fis.close(); 
+2
source

All Articles