Free Support Forum - aspose.com

Can i Find a String in a Particular Column Usinf Find Options

Hi,
I am Trying to Find the String in a particular column but as a result it is giving me all the cells from the sheet.
Here is My Code.

Code:-

int num=cells.getMaxDataRow();

FindOptions findOptions = new FindOptions();
findOptions.setLookinType(FindOptions.SEARCH_BY_COLUMNS);
Cell prevCell = null;
for (int n1=0;n1<=num;n1++)
{
{
Cell cell1=cells.getCell(n1,3);

cell1 = cells.find(“Hello”,prevCell,findOptions);
if(cell1!=null)
{
System.out.println(cell1.getValue());
System.out.println("Name of the cell containing formula: " + cell1.getName());
Style style = cells.getCell( n1,3).getStyle();
style.setColor(Color.MAGENTA);
cell1.setStyle(style);
prevCell = cell1;
}
}
}

Hi,

FindOptions.SEARCH_BY_COLUMNS will find string column by column. Means, it will first search for string in a particular column then move to next column and search there and then move to next column so on.

It will find all the strings though.

Hi,
Is there any Other way to find it only in columns. with find options?

Hi,

I think no. Please see the image below and the sample xlsx file for further illustration.

However, you can use this condition to restrict yourself to single column. Please see the pseudo code below.

Java


int yourColumn=2; //suppose you are looking third column

while(nextCellFound.getColumnIndex() == yourColumn)
{
//Keep looking for next cells containing your search value
}

Screenshot: