Forum Discussion

babusr01's avatar
babusr01
Contributor
9 years ago

write Excel Data with poi api in Groovy script - SOAPUI 5.0.0

Hi ,

 

I am using poi api to read Response Data and write in Excel file - with Groovy script step.

But while declaring FileOutputStream object , getting below error.

Could some one help me.

 

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.apache.poi.hssf.usermodel.HSSFWorkbook(java.io.FileOutputStream) error at line: 33

 

below is my code

 

 

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;

//Get the Results file path
def path_O = projpath+"\\Result\\"+ "USZIPCODES" +".xls"


//Create a new workbook using POI API
srcBook = new HSSFWorkbook(new FileInputStream(new File(path_I)))
desBook = new HSSFWorkbook(new FileOutputStream(new File(path_O)));

 

 

  • JKambli's avatar
    JKambli
    9 years ago

    Thanks for the update. Can you mark this post as resolved.

     

  • Here is a sample script,

     

    import java.io.File;
    import java.io.FileInputStream;
    import java.util.Iterator;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
     
    FileInputStream file = new FileInputStream(new File('C:\\sample.xls'));
    XSSFWorkbook workbook1 = new XSSFWorkbook(file)
    XSSFSheet sheet1 = workbook1.getSheetAt(0)
    Iterator ite = sheet1.rowIterator();
     
    headers=[]
     
    Row row = ite.next();
    Iterator<Cell> cite = row.cellIterator();
    while(cite.hasNext()){
            Cell c = cite.next();
            headers << c.toString()
    }
     
    file.close();
     
    log.info headers
     
    for ( i in headers ) {
      testRunner.testCase.testSteps["DataSource"].addProperty(i);
    }
      • JKambli's avatar
        JKambli
        Staff

        Thanks for the update. Can you mark this post as resolved.

         

    • timaharrison's avatar
      timaharrison
      Occasional Contributor

      Hi Could someone please let me know what JAR files need to be imported to the "C:\Program Files\SmartBear\SoapUI-X.X.X\lib" folder for this to work?  I have the JAR files listed below and get error "java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap" when running this code

       

      dom4j-1.6.1

      poi-3.15

      poi-ooxml-3.15

      poi-ooxml-schemas-3.15

      xmlbeans-2.6.0

       

      Thanks

      • babusr01's avatar
        babusr01
        Contributor

        Hi 

        You can try in keeping in \Exe folder..