deepak.mr888
deepak.mr888

Reputation: 349

Fetch excel records with filters using Apache.poi in Java

I am a little familiar to apache.poi, I know how to read / write in excel using Apache.poi in Java. I want to know that how can I fetch records from excel with applying some filters on a particular column or two using my script?

Here is the example what I want :

Header1 Header2 Header3
1 A 11 
2 A 13
3 A 11
4 B 12
5 B 13
6 B 12

How can I get what values are there under Header1 if I select 'A' from 'Header2' and what values are there under 'Header1' if I select '11' from 'Header3'.

Basically I just want to apply filters on 'Header2','Header3' to find what values are there under 'Header1' for the respective filter.

Please let me know the answer. Thanks.

Upvotes: 1

Views: 889

Answers (1)

Avyaan
Avyaan

Reputation: 1313

I dont think there is direct method in apache poi for filters.You have to manage it in code.

-- first you have to write one method that will return list of row index(in which your value occurs)

-- one the base of row indexes,you can iterate and get the values of all other cell.

sample :

 list getRowIndexes(int filterCellValue){
// iterate over row
if(row.getcell.getcellvalue == filterCellValue){
list.add(currentrowIndex);
}

hope it may help.

}

Upvotes: 1

Related Questions