File io org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存失败
我面临File io org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存失败,file-io,excel-2010,export-to-excel,File Io,Excel 2010,Export To Excel,我面临org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存包时出错:无法使用marshallerorg.apache.poi.openxml4j.opc.internal.marshallers将部分/docProps/app.xml保存到流中。DefaultMarshaller@7c81475b 在每个测试场景执行完成后,尝试将每个测试场景结果(通过或失败)写入Excel工作表(.xlsx)时出现异常。为此,我编写了以
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:保存包时出错:无法使用marshaller
org.apache.poi.openxml4j.opc.internal.marshallers将部分/docProps/app.xml保存到流中。DefaultMarshaller@7c81475b
在每个测试场景执行完成后,尝试将每个测试场景结果(通过或失败)写入Excel工作表(.xlsx)时出现异常。为此,我编写了以下两个不同的模块。请告诉我问题出在哪里以及如何解决
//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);
}
}
//将结果写入报表的方法
public void putResultstoReport(字符串值[])
{
int j=已执行的Nooftimes;
NoofTimesExecuted++;
XSSFRow row=sheet.createRow(j);
对于(int i=0;i我今天遇到了这个问题,并且已经解决了
问题出在putResultstoReport()
你不能在你的周期中wb.write(fileOut);
决议:
首先调用putResultstoReport();
然后wb.write(fileOut);
我也遇到了这个错误
我发现我的错误是由于我多次打开同一个文件/工作簿造成的
因此,我建议您在尝试关闭之前确保只打开一次。我也有类似的问题。
最后我得到了原因,这就是下面jar文件的版本被覆盖的原因
org.apache.xmlgraphics:batik-dom
因此,我在下面添加了依赖项,现在它运行良好
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-dom</artifactId>
<version>1.8</version>
</dependency>
org.apache.xmlgraphics
蜡染dom
1.8
此jar包含对xalan的依赖项。
要生成报告,需要xalan。如果发生超时,可能会发生这种情况。我的代码适用于小数据集,并在大数据集时抛出此错误。我也有同样的问题。
当我缩短输出excel文件名时,它停止了。我遇到了同样的问题,用户刷新页面并在上一个请求完成之前再次发送请求。
创建名称时,在名称中使用毫秒以避免名称与名称代码中的这些更新冲突创建解决了上述问题
String sheetName="projectName"+System.currentTimeMillis() + ".xlsx"
FileOutputStream fileOut = new FileOutputStream(sheetName);
workbook.write(fileOut);
fileOut.close();
错误信息甚至不是很好的英语。如果有人可以试一试的话,我这里有悬赏