我是POI的新手,我要求在两个不同的Excel工作表中搜索给定的字符串列表,这些工作表会出现一次或多次搜索字符串 .

现在,我使用Cell itereator迭代所有行来搜索字符串,

for (String searchString : SearchList){
List<Row> matchedRows = getMatchedRows(searchString);

}

public List<Row> getMatchedRows(String searchString)
List<Row> rowsMatched = new ArrayList();
(Row rowOfSheet : workSheet) {
if(rowOfSheet.getCell(index).getStringCellValue().equalsIgnoreCase(searchString)) {
    rowsMatched.add(rowOfSheet)
           }
     }
}

但是性能会受到影响,因为我在ExcelSheet以及searchList中都有大量记录 . 所以我尝试使用“匹配”公式来使用Evaluator获取匹配行的索引,但是当我尝试执行以下操作时,我无法使用正确的语法:

"MATCH('C:\\Files\\[File1.xlsx]sheet1'!$A$2,'C:\\Files\\[File2.xlsx]sheet2'!$B$2:$B$741,0)"

这给了我以下例外:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid sheetIndex: -1.
at org.apache.poi.ss.formula.SheetRefEvaluator.<init>(SheetRefEvaluator.java:39)
at org.apache.poi.ss.formula.OperationEvaluationContext.createExternSheetRefEvaluator(OperationEvaluationContext.java:97)
at org.apache.poi.ss.formula.OperationEvaluationContext.getRef3DEval(OperationEvaluationContext.java:249)
at org.apache.poi.ss.formula.WorkbookEvaluator.getEvalForPtg(WorkbookEvaluator.java:656)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:527)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:288)

如何在公式String中指定完整文件路径 . 我重新评估了以下内容,但这对我来说并不适用 .

http://stackoverflow.com/questions/10915475/java-poi-xssf-formulaevaluator

怎么解决这个问题 . 任何建议和解决方案都非常有帮助 . 提前致谢 . 请尽快给我一些解决方案 .