1 回答

TA貢獻1851條經(jīng)驗 獲得超5個贊
您應該為您創(chuàng)建一個地圖,
not-to-be-contacted-manufacturers
名稱作為鍵,制造商作為值。然后您可以使用containsKey
而不是不斷迭代mfgs-list
.您應該使用 的結果遍歷行
rowIterator
。您不需要另一個迭代器。局部變量不應該以大寫字母開頭(
DNC_Reason
-更好的名字是dncReasonCell
)
假設制造商單元格已填充的示例代碼(getStringValue()
可能會導致NullPointerException
未給出適當?shù)闹担?,樣式變量已初始化并且您有一個不可聯(lián)系的制造商地圖:
Iterator<Row> rowIterator = spreadsheet.rowIterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Cell dncReasonCell = row.getCell(1);
if (dncReasonCell == null) {
dncReasonCell = row.createCell(1, CellType.STRING);
}
Cell manufacturerCell = row.getCell(0);
String manufacturerNameForDncTest = Pattern
.compile("[\\.$|,|;|'|\\s|-]|\\b(LLC|Company|Incorporated|Co|Manufacturer|The|Limited|Ltd|Inc)\\b", Pattern.CASE_INSENSITIVE)
.matcher(manufacturerCell.getStringCellValue()).replaceAll("");
if (notToBeContactedManufacturers.containsKey(manufacturerNameForDncTest)) {
manufacturerCell.setCellStyle(style);
dncReasonCell.setCellValue(notToBeContactedManufacturers.get(manufacturerNameForDncTest).getDNCReason());
} else {
dncReasonCell.setCellValue("");
}
}
添加回答
舉報