部品番号のスプレッドシートのデータを読み取るために Apache POI を使用しています。データベースで部品番号を調べます。部品の CAD 図面がある場合は、部品番号のセルを緑に、ない場合は赤にします。処理が完了すると、スプレッドシートが保存されます。私が抱えている問題は、その列のすべてのセルが緑色になることです。私はコードをステップ実行しました。部品番号を検索するロジックは正常に機能しており、セルの色を決定し、色と塗りつぶしを設定するロジックも同様に機能しているようです。ここで私が間違っていることはありますか?
ありがとう。
//Check the parts
for(int r=1;r<sheet.getPhysicalNumberOfRows();r++) {
String partNumber = null;
switch(cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
long pNum = (long) cell.getNumericCellValue();
partNumber = String.valueOf(pNum);
break;
case HSSFCell.CELL_TYPE_STRING:
partNumber = cell.getStringCellValue();
break;
default:
logger.info("Part Number at row " + r + " on sheet " + partList.getSheetName(s) + "is of an unsupported type");
}
try {
List<String> oldMaterialNumbers = getOldMaterialNumbers(partNumber);
boolean gotDrawing = checkPartNumber(oldMaterialNumbers, partNumber);
//If there's a drawing then color the row green, if not red.
short bgColorIndex = gotDrawing
?HSSFColor.LIGHT_GREEN.index //42
:HSSFColor.RED.index; //10
HSSFCell curCell = row.getCell(partNumberColumn);
HSSFCellStyle curStyle = curCell.getCellStyle();
curStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
curStyle.setFillForegroundColor(bgColorIndex);
curCell.setCellStyle(curStyle);
}catch(Exception e) {
throw e;
}
}