使用带有ArrayList的Apache POI更新Excel表

我必须更新现有的Excel表格来捕获结果。 结果应该添加在我的Excel表格中的特定行而不是按顺序。 这些值在ArrayList中提供,但最后一个索引仅添加到Excel表单中。 以下是代码:

public static ArrayList<String> writeResult(String filename, ArrayList<String> code, ArrayList<String> value) throws IOException, InvalidFormatException{ FileInputStream fis=new FileInputStream(filename); Workbook wb=WorkbookFactory.create(fis); Sheet sh=wb.getSheet("DataSheet-Execution"); String statusString=""; int count = 0; Row row=sh.getRow(5); for(int k=0;k<code.size();k++){ for(int j=5;j<=28;j++) { for(int i=0;i<=row.getLastCellNum();i++) { if(row.getCell(i) != null) { row = sh.getRow(j); Cell status=row.getCell(4); statusString = status.toString(); if(statusString.equals("Y")) { Cell cellxAction=row.createCell(26); Cell cellRes=row.createCell(27); cellxAction.setCellValue(code.get(k).toString()); cellRes.setCellValue(value.get(k).toString()); } } } } } FileOutputStream fos=new FileOutputStream(filename); wb.write(fos); fos.close(); System.out.println("Excel File Written"); return value; }