第二for循环未运行

时间:2018-08-21 20:23:13

标签: java apache apache-poi

我正在使用Apache POI读取和写入Excel文件。但是,当试图在一个工作簿中写入两个不同的工作表时,第二个for循环没有执行。因此,只有第一个工作表被写入,而第二个工作表则没有。

for (int r = 4; r < outTotalRows1; r++) {
    row2 = outSheet1.getRow(r);
    if (row2.getCell(3) == null) {
        for (int t = 3; t <= 47; t++) {
            outCell = row2.createCell(t);
            outCell.setCellValue(BSMeanArray[t - 3]);
            FileOutputStream outWrite = new FileOutputStream(new File(outputFileName));
            outWorkbook.write(outWrite);
            outWrite.close();
        }
    }
    if (row2.getCell(50) == null) { // if the velocity cell is == null, then set cell value to array established and then break
        for (int u = 50; u < 94; u++) {
            outCell = row2.createCell(u); // maybe this line wrong?
            outCell.setCellValue(BFMeanArray[u - 50]);
            FileOutputStream outWrite = new FileOutputStream(new File(outputFileName));
            outWorkbook.write(outWrite);
            outWrite.close();
        }
    }
}

// THIS LOOP NOT EXECUTING
for(int r = 4; r < outTotalRows2; r++){
    System.out.println("executed");
    row3 = outSheet2.getRow(r);
    if (row3.getCell(3) == null) {
        for (int u = 3; u <= 47; u++) {
            outCell = row3.createCell(u);
            outCell.setCellValue(FFSMeanArray[u - 3]);
            FileOutputStream outWrite = new FileOutputStream(new File(outputFileName));
            outWorkbook.write(outWrite);
            outWrite.close();
        }
    }
    if (row3.getCell(50) == null) {
        for (int u = 50; u <= 94; u++) {
            outCell = row3.createCell(u);
            outCell.setCellValue(FFFMeanArray[u - 50]);
            FileOutputStream outWrite = new FileOutputStream(new File(outputFileName));
            outWorkbook.write(outWrite);
            outWrite.close();
        }
    }
}

0 个答案:

没有答案