Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 2

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.
*
* @Param propertyKey
* the property key
* @Return 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;
}

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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. 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

@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.