我正在使用Apache Poi将数据复制到excel工作表中。我想像同一张纸一样从D列复制到G列。但是,当我尝试从D列复制到G列时,出现异常-
INFO [http-nio-9080-exec-8] org.apache.cxf.phase.PhaseInterceptorChain.doDefaultLogging应用程序{http://service.ccc.com/} excelS引发了异常,现在展开:org.apache.poi.openxml4j。 exceptions.OpenXML4JRuntimeException:规则M2.4异常:永远不会发生此错误,如果是这样,请向开发团队发送邮件,谢谢! 警告[http-nio-9080-exec-8] org.apache.cxf.phase.PhaseInterceptorChain.unwind拦截器org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor@33b5e6de上的handleFault异常 org.apache.cxf.interceptor.Fault:规则M2.4异常:永远不会发生此错误,如果是这样,请向开发团队发送邮件,谢谢!
请告诉我问题出在哪里以及如何解决。.
public class excelS {
public void copyColumn(String fileId, int sourceCol, int targetColumn) {
Long l = Long.valueOf(fileId);
excelDetail x = (excelDetail) componentList.get(l);
Sheet sheet = x.wb.getSheetAt(x.wb.getSheetIndex(x.sheetName));
for (int rId = 0; rId <= sheet.getLastRowNum(); rId++) {
Row row = sheet.getRow(rId);
if (row != null) {
Cell oldCell = row.getCell(sourceCol);
if (oldCell != null) {
Cell newCell = row.createCell(targetColumn, oldCell.getCellType());
cloneCellWithStyle(newCell, oldCell);
} else {
row.createCell(targetColumn, Cell.CELL_TYPE_BLANK);
}
}
}
try {
FileOutputStream fos = new FileOutputStream(x.path);
x.wb.setForceFormulaRecalculation(true);
x.wb.write(fos);
fos.close();
rm.setResult("success");
rm.setValue("column has been copied.");
} catch (IOException e) {
e.printStackTrace();
rm.setResult("error");
rm.setValue(e.getMessage());
}
}
}