int j = 1;
int i = Integer.parseInt(source.getProperty("表單數據從第幾行開始")) - 1;
int lastnum = getNum(source.getProperty("fileName"));
for (int k = 0; k < conditions.length; k++) {
System.out.println(conditions[k]);
switch (conditions[k]) {
case "1":
for (; i < lastnum; i++) {
XSSFRow readrow = readsheet.getRow(i);// 獲取輸入行
Process p = new ProcessRow();
if (p.panduan1(readrow)) {
System.out.println("get1");
XSSFSheet sheet = sc.getSheetAt(0);
XSSFRow outputrow = sheet.createRow(j++);
p.process1(readrow, outputrow);
p.process2(readrow, outputrow);
p.process3(readrow, outputrow);
p.process4(readrow, outputrow);
}
}
case "2":
for (; i < lastnum; i++) {
XSSFRow readrow = readsheet.getRow(i);// 獲取輸入行
Process p = new ProcessRow();
System.out.println("get");
if (p.panduan2(readrow)) {
System.out.println("get2");
XSSFSheet sheet = sc.getSheetAt(0);
XSSFRow outputrow = sheet.createRow(j++);
p.process2(readrow, outputrow);
}
}
default:
break;
}
輸出結果
1
get1
get1
2
3
4
輸入完畢
為什麼case 2沒執行
i值沒有還原,導致執行完case 1時i > lastnum,當執行到case 2的時候i依舊大於lastnum,for循環直接跳出,因此為執行。
你的程序怎麼case之後不跟break?case之後不跟break就會導致進入switch之後所有的case均執行一遍。