1 回答
TA贡献1788条经验 获得超4个赞
您应该为您创建一个地图,
not-to-be-contacted-manufacturers
名称作为键,制造商作为值。然后您可以使用containsKey
而不是不断迭代mfgs-list
.您应该使用 的结果遍历行
rowIterator
。您不需要另一个迭代器。局部变量不应该以大写字母开头(
DNC_Reason
-更好的名字是dncReasonCell
)
假设制造商单元格已填充的示例代码(getStringValue()
可能会导致NullPointerException
未给出适当的值),样式变量已初始化并且您有一个不可联系的制造商地图:
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("");
}
}
添加回答
举报