org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存失败 [英] org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save
问题描述
我正面对org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save:an error occurs while saving the package : The part /docProps/app.xml fail to be saved in the stream with marshaller <br/> org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@7c81475b
在每个测试方案执行完成后尝试将每个测试方案结果(PASS或FAIL)写入Excel工作表(.xlsx)时发生异常.为此,我编写了以下两个不同的模块.
Exception when try to write the each test scenario result(PASS or FAIL) into Excel sheet(.xlsx) after the each test scenario execution completion. I write the following two different modules for this purpose.
请告诉我问题出在哪里以及如何解决..
Please tell me where is the problem and how to resolve it..
//Method for writing results into Report
public void putResultstoReport(String values[])
{
int j=NoofTimesExecuted;
NoofTimesExecuted++;
XSSFRow row = sheet.createRow(j);
for(int i=0;i<values.length;i++)
{
XSSFCell cell = row.createCell(i);
cell.setCellValue(values[i]);
}
try {
System.out.println("Times:"+NoofTimesExecuted);
wb.write(fileOut);
}
//fileOut.flush();
//fileOut.close();
}
catch(Exception e) {
System.out.println("Exception at closing opened Report :"+e);
}
//Method for Creating the Excelt Report
public void createReport()
{
String FileLocation = getProperty("WorkSpace")+"//SCH_Registration//OutPut//TestResults.xlsx";
try {
fileOut = new FileOutputStream(FileLocation);
String sheetName = "TestResults"; //name of sheet
wb = new XSSFWorkbook();
sheet = wb.createSheet(sheetName);
fileOut.flush();
fileOut.close();
}
catch(Exception e)
{
System.out.println("Exception at Create Report file:"+e);
}
}
推荐答案
我也遇到此错误.
我发现自己的错误是由于多次打开同一文件/工作簿引起的.
I found my mistake was caused because I was opening the same file / workbook multiple times.
因此,我建议确保在尝试关闭之前仅打开一次.
So I would recommend to make sure you are opening just once before attempting to close as well.
这篇关于org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!