获取以下错误"Typed variable declaration : Class: Workbook not found in namespace"



我收到以下错误,

2019-01-24 12:11:27,579 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.threads.JMeterVariables; import org.apache.poi.ss.userm . . . '' : Typed variable declaration : Class: Workbook not found in namespace.
2019-01-24 12:11:27,579 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  Sourced file: inline evaluation of: ``import org.apache.jmeter.threads.JMeterVariables; import org.apache.poi.ss.userm . . . '' : Typed variable declaration : Class: Workbook not found in namespace

我正在尝试执行以下代码

    import org.apache.jmeter.threads.JMeterVariables;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import java.io.File;
    import java.io.FileInputStream;
    log.info("before");
    FileInputStream excelFile = new FileInputStream(new File("File Path"));
    log.info("excelFile");
    Workbook wb = new XSSFWorkbook(excelFile);
    excelFile.close();
    log.info("before3");
    Sheet s = wb.getSheetAt(0);
    //Sheet s = wb.getSheet("Bulk Upload");
    int lines = FileUtils.readLines(new File("File Path")).size(); // get lines count
    //vars.put("lines", String.valueOf(lines)); // store the count into "lines" variable
    int i;
    for(i=0; i<=lines;i++)
    {
    log.info("during");
    Row row = s.getRow(i);
    Cell a1 = row.getCell(0);
    String a1Value = a1.getStringCellValue();
    Cell a2 = row.getCell(1);
    String a2Value = a2.getStringCellValue();
    Cell a3 = row.getCell(2);
    String a3Value = a3.getStringCellValue();
    Cell a4 = row.getCell(3);
    String a4Value = a4.getStringCellValue();
    }
    log.info("after");

请让我知道为什么我会收到此错误以及我应该在哪里进行更正

发生这种情况是因为您的类路径上没有正确设置Apache POI JAR文件。您需要将其添加到类路径中。

或者,如果您确定确实在类路径中包含 JAR 文件,请确保您没有遇到菱形依赖项问题并同时使用两个不同的版本。根据另一个关于类似(尽管显然不是重复)问题的答案,Apache POI 不能很好地与类路径上的多个版本配合使用。

最新更新