创建错误的curropted.xlsx文件 - 无法找到匹配的构造函数:org.apache.poi.xssf.usermodel.XSSFWorkbook(java.io.FileOutputStream)

时间:2017-12-26 08:30:22

标签: groovy apache-poi soapui

使用以下代码,我尝试在项目路径中创建一个输出.xlsx文件,其中包含一个工作表创建和标题分配。使用0kb创建文件。打开文件时,它会将消息显示为“文件格式或文件扩展名无效。验证文件是否已损坏,文件扩展名是否与文件格式匹配。” soap ui也会显示错误消息“找不到匹配的构造函数:org.apache.poi.xssf.usermodel.XSSFWorkbook(java.io.FileOutputStream)”

//用于创建文件的代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; 
import java.util.*; 
import java.lang.*;
import jxl.*; 
import jxl.write.*;
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;
import org.apache.poi.ss.util.* ;

def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context) 
def projectPath = groovyUtils.projectPath 


//creating the output sheet 
FileOutputStream outfile = new FileOutputStream(new File(projectPath+"\\"+outputFileName));
XSSFWorkbook writableWorkbook = new XSSFWorkbook(outfile);
XSSFSheet writableSheet = writableWorkbook.createSheet("Output Sheet");

Row header = writableSheet.createRow(0);
header.createCell(0).setCellValue("TestCase");
header.createCell(1).setCellValue("Parameter");
header.createCell(2).setCellValue("Actual");
header.createCell(3).setCellValue("Expected");
header.createCell(4).setCellValue("Status");

context["Outputdata"]=writableSheet 

writableWorkbook.write();
writableWorkbook.close();
  

堆栈跟踪:

     

Tue Dec 26 13:50:10 GMT + 05:30 2017:错误:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:org.apache.poi.xssf.usermodel.XSSFWorkbook(java.io.FileOutputStream )      groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:org.apache.poi.xssf.usermodel.XSSFWorkbook(java.io.FileOutputStream)       at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1550)       at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1404)       在org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:46)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)       在Script19.run(Script19.groovy:72)       在com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)       在com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)       在com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)       在com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)       在com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)       在com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)       在com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:128)       at java.util.concurrent.Executors $ RunnableAdapter.call(Unknown Source)       at java.util.concurrent.FutureTask.run(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

1 个答案:

答案 0 :(得分:0)

如果使用下面的代码,则代替上面的代码,使用创建的标题成功创建文件。

XSSFWorkbook WritableWorkbook = new XSSFWorkbook() FileOutputStream fileOut = new FileOutputStream(new File(projectPath+"\\"+outputFileName))