0

I've a problem with importing excel sheet data to work with Java. I've a Table that look likes the following.


Image | Name | Order


1011V | Holly | ON-10121


As you can see, I've column Headings ,

  • Image
  • Name
  • Order

I want to get the Column Name like A , B or C in Excel, given that I've provided the Column Headings ( Cell Values ) Image , Name or Order.

For Example Something like :- getExcelColumnName("Image") , getExcelColumnName()

Danny
  • 1
  • 1
  • 2

3 Answers3

0

Suppose you want to know header no of 5th Column then you have cell no 5. Take cell of row 1 and 5th Column by.

 Cell cell = Sheet1.getRow(0).getCell(5);

now take a string

 String cellNumber = cell.getReference(); 

It will give you E1. I have given you an idea of using cell.getReference(); you can use it by many ways to get the desired result.

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
  • 1
    In which api yuo got cell.getreference() method, I am using Apache POI and cell do not have any such method – kavinder Nov 05 '14 at 12:51
0

I found the following API will work: CellReference.convertNumToColString(5) will return "F"

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
Yang
  • 11
0

I got this answer usefull..

  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)
      {}
  }

static

      Cell cell = spreadsheet.getRow(0).getCell(2);
      tmp=64+cell.getColumnIndex();
      //convert ascii code to character
      System.out.println(Character.toString((char)tmp));

Visit Full Describe : Get columns' names in Excel file using Apache POI

Community
  • 1
  • 1
Chetan Bhagat
  • 610
  • 6
  • 21