how to find excel column number from the column name in AEM | Community
Skip to main content
Level 2
April 5, 2022
Solved

how to find excel column number from the column name in AEM

  • April 5, 2022
  • 1 reply
  • 713 views

Hi Team.

 

In our project, we are using an excel sheet which will be converted into Json. we are using a config file to map column like first column will be mapped to 0 and second column mapped to 1 and so on. 

 

Our logic is mapping using column numbers which is causing problem when in between any column is deleted.

 

Is there any way to get column number using column name. ??

 

In the below code, we are sending property key which will hold column no but I would like send property key containing column and get column number.

/**
* Gets the int val from props.
*
* @90521 propertyKey
* the property key
* @2007960 the int val from props
*/
public static int getIntValFromProps(String propertyKey) {
int colNum = -1;
// final String colNumStr = PropertiesHelper.fetchPropertyFromCache(propertyKey);
final String colNumStr = PropertiesHelper.fetchPropertyFromCache(propertyKey);

if (colNumStr != null && !"".equals(colNumStr.trim())) {
colNum = Integer.parseInt(colNumStr.trim());
}
return colNum;
}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nitin_laad

@prash0905  how are you generating JSON from xlsx, may I know the API name?

if your ask is to get column name in transformed JSON from xlsx, Using   https://poi.apache.org/apidocs/5.0/ API you should be able to get required results in generated JSON. 

1 reply

Nitin_laad
Community Advisor
Nitin_laadCommunity AdvisorAccepted solution
Community Advisor
April 5, 2022

@prash0905  how are you generating JSON from xlsx, may I know the API name?

if your ask is to get column name in transformed JSON from xlsx, Using   https://poi.apache.org/apidocs/5.0/ API you should be able to get required results in generated JSON.