2017-03-08 53 views
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)); 

這隻打印與正則表達式匹配的第一個單元格。我如何獲得與正則表達式匹配的所有單元格的集合?正則表達式評估以便返回所有匹配的單元格

+0

如果您在下次調用查找時將第一個查找的結果作爲第二個參數傳遞,那麼會發生什麼,等等,直到結果爲空? – laune

回答

0

你必須使用一些循環查找每個工作表中的匹配單元,請參閱您參考示例代碼段: 如 示例代碼:

.......... 
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); 

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

我的工作是支持開發者/傳播者在Aspose。