0
               FindOptions opt = new FindOptions();

            opt.setRegexKey(true); 
            opt.setLookAtType(LookAtType.ENTIRE_CONTENT);
            Cells cells = workbook.getWorksheets().get(1).getCells();
            String regex = "<.*>";

            System.out.println(cells.find(regex, null, opt));  

This only prints the first cell that matches the regex . How can I get a collection of all the cells that match the regex?

user4790067
  • 451
  • 2
  • 6
  • 12
  • What happens if you pass the result of the first find as second parameter in the next call to find, and so on, until the result is null? – laune Mar 08 '17 at 08:38

1 Answers1

0

You got to use some loop to find each cell that matches in the worksheet, see the sample code segment for your reference: e.g Sample code:

..........
Cells cells = workbook.getWorksheets().get(1).getCells();
Cell cell;
Cell prevcell = null;
String regex = "<.*>";
FindOptions opt = new FindOptions();

            opt.setRegexKey(true); 
            opt.setLookAtType(LookAtType.ENTIRE_CONTENT);


do {

                    cell = cells.find(regex, prevcell, opt);
 System.out.println("Name:" + cell.getName() + " Value:" + cell.getStringValue());  

                    if (cell == null)
                        break;

                    prevcell = cell;

                } while (cell != null);

................

I am working as Support developer/ Evangelist at Aspose.

Amjad Sahi
  • 1,813
  • 1
  • 10
  • 15