Что не так с этим циклом. HSSF
В этом коде я ищу элемент списка списков, который содержится в списке. Почему, когда я нашел нужные элементы, он начинает плохо работать. Если я найду другой элемент, который содержится в списке, эта ячейка должна быть заполнена синим цветом, но этого не происходит.
HSSFWorkbook workbook = new HSSFWorkbook(file);
CreationHelper createHelper = workbook.getCreationHelper();
//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(0);
CellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(IndexedColors.LIME.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
CellStyle style2 = workbook.createCellStyle();
style2.setFillForegroundColor(IndexedColors.RED.getIndex());
style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
CellStyle style3 = workbook.createCellStyle();
style3.setFillForegroundColor(IndexedColors.BLUE.getIndex());
style3.setFillPattern(CellStyle.SOLID_FOREGROUND);
for (int i=0;i<ListOfList.size();i++) {
int count=0;
label1:
for (int j=0;j<ListOfList.get(i).size();j++) {
Row row = sheet.getRow(i);
for (int k=0;k<List.size();k++){
if (List.get(k).equals(ListOfList.get(i).get(j))) {
count++;
if (count==1) {
System.out.println("("+List.get(k)+") ASU <--> ("+ListOfList.get(i).get(j)+") RZS "+"String: "+i+" Column: "+j);
row.createCell(2+j).setCellValue(ListOfList.get(i).get(j));
row.getCell(2+j).setCellStyle(style);
Row row2 = sheet.getRow(k);
row2.createCell(0).setCellValue(List.get(k));
row2.getCell(0).setCellStyle(style);
continue label1; }
else{ // count!=1
System.out.println("Another element contain!");
row.createCell(2+j).setCellValue(ListOfList.get(i).get(j));
row.getCell(2+j).setCellStyle(style3);}
}
else {row.createCell(2+j).setCellValue(ListOfList.get(i).get(j));
row.getCell(2+j).setCellStyle(style2);}
}
}
}
Результат сейчас:
(222) ASU <--> (222) RZS String: 0 Column: 1
Another element contain!
Another element contain!
Another element contain!
(233) ASU <--> (233) RZS String: 1 Column: 1
(244) ASU <--> (244) RZS String: 2 Column: 1
Another element contain!
Another element contain!
Another element contain!
Another element contain!
Почему это не залито СИНИМ????
1 ответ
Нашел проблему.
else{ // count!=1
System.out.println("Another element contain!");
row.createCell(2+j).setCellValue(ListOfList.get(i).get(j));
row.getCell(2+j).setCellStyle(style3);}
}
else {row.createCell(2+j).setCellValue(ListOfList.get(i).get(j));
row.getCell(2+j).setCellStyle(style2);}
2-й еще перезаписать 1-й еще, что жаль (