0

I am getting error when trying to create xlsx file using Jmeter. actually I already try using HSSF (for .xls) and it is works fine. But when I am trying to change it using xlsx, I am getting error. I already copy the jar file for poi and poi-ooxml on jmeter lib file. here is my simple script :

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
import java.lang.String;
import java.lang.Object;

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sample sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("HENCIN");

try {
    FileOutputStream out = new FileOutputStream(new File("D:\\Jmeter\\testhencin.xlsx"));
    workbook.write(out);
    out.close();
    System.out.println("Excel written successfully..");
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

Actually when I am trying to find the error, the problem are getting from this line :

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sample sheet");

Please someone help me to figure it out. it works on HSSF but on XSSF it is not working. I am getting error :Response code: 500

Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  org/apache/xmlbeans/XmlObject
Hendrione
  • 225
  • 1
  • 5
  • 18
  • 1
    Did you [copy in all the Apache POI dependencies as handily listed on this page on the site](http://poi.apache.org/overview.html#components)? If not, what happens when you read the docs and do so? – Gagravarr Nov 08 '16 at 09:15
  • yeah... I still missing some dependencies. now it works like a charm. I use this : poi-3.11.jar , poi-excelant-3.11.jar, poi-ooxml-3.11.jar , poi-ooxml-schemas-3.11,jar , poi-scratchpad-3.11.jar, xmlbeans-2.6.0.jar – Hendrione Nov 08 '16 at 09:43

1 Answers1

1

I would suggest:

  1. Catching all the possible exceptions and printing the stacktrace to jmeter.log file as well
  2. Re-throwing the exception to make sure you won't get false positive sampler result, something like:

    } catch (Throwable e) {
        e.printStackTrace();
        log.info("Error in Beanshell", e);
        throw e;
    } 
    

With regards to your question, most likely it is due to missing XMLBeans jar in JMeter classpath. I would suggest the following:

  • Get "clean" installation of the latest JMeter version
  • Download the latest version of tika-app.jar and drop it to JMeter's "lib" folder
  • Restart JMeter to pick the jar up

Using Tika you will get all the necessary libraries bundled, moreover, you JMeter will display content of the binary files in the View Results Tree listener. See How to Extract Data From Files With JMeter article for more details.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133