0

我收到以下错误,

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

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

4

1 回答 1

0

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

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

于 2019-01-24T07:55:26.243 回答