java - 第二个for循环没有运行
问题描述
我正在使用 Apache POI 读取和写入 excel 文件。但是,在尝试写入 1 个工作簿中的两个不同工作表时,我的第二个 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();
}
}
}
解决方案
推荐阅读
- java - 在本地应用程序中使用 AOSP 中已弃用的类
- vue.js - 在 VueJS 和 VueI18n 运行时动态加载翻译
- android - android 中的 Html.fromHtml 是否仅适用于显示的文本?
- padding - 使用分配给 w3.css 的“w3-container”类的 padding-top=padding-bottom="0.01em" 是什么意思?
- javascript - 在 WebGL 中显示存储在 .js 文件中的“模型”
- javascript - 在 React 中创建标签栏动画的转换问题
- vba - 访问运行时错误“-2147352567 (8002009)”无法为该对象赋值
- ruby-on-rails - 如何使用 JIRA Rails gem 中的自定义“Reporter”创建问题
- java - 如何找到运行时 int 转换错误的修复程序?
- swift - 在 XCode Simulator 中启动具有位置服务使用权限的应用程序