第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Apache POI 為相鄰列設置單元格值?

如何使用 Apache POI 為相鄰列設置單元格值?

浮云間 2023-06-14 15:00:13
我的目標是遍歷一個已有的 2 列 Excel 電子表格。一個稱為制造商,另一個稱為 DNC 或請勿聯(lián)系。我想遍歷我擁有的制造商列表,并將那些不應聯(lián)系的標記為紅色,并在制造商名稱列表旁邊的相鄰空白欄中標記一些為什么無法聯(lián)系他們的注釋。我在下面附上了我的代碼。我將每個制造商對象的字段存儲在一個名為“mu”的鏈表中,它們是“name”和“DNC_Reason”。Iterator<Row> rowIterator2 = spreadsheet.iterator();while (rowIterator2.hasNext()) {    Row row2 = rowIterator2.next();    Cell DNC_Reason = row2.getCell(1);    if(row2.getCell(1) == null) {        row2.createCell(1);    }    Iterator<Cell> cellIterator2 = row2.cellIterator();    while (cellIterator2.hasNext()) {        Cell cell = cellIterator2.next();        Pattern p = Pattern.compile("[\\.$|,|;|'|\\s|-]|\\b(LLC|Company|Incorporated|Co|Manufacturer|The|Limited|Ltd|Inc)\\b", Pattern.CASE_INSENSITIVE);        Matcher m = p.matcher(cell.getStringCellValue());        String s = m.replaceAll("");        for (Manufacturer mu : mfgs) {            if (cell.getColumnIndex() == 0 && mu.getName().equals(s)) {                cell.setCellStyle(style);                DNC_Reason.setCellValue(mu.getDNCReason());            }        }    }}
查看完整描述

1 回答

?
江戶川亂折騰

TA貢獻1851條經(jīng)驗 獲得超5個贊

  1. 您應該為您創(chuàng)建一個地圖,not-to-be-contacted-manufacturers名稱作為鍵,制造商作為值。然后您可以使用containsKey而不是不斷迭代mfgs-list.

  2. 您應該使用 的結果遍歷行rowIterator。您不需要另一個迭代器。

  3. 局部變量不應該以大寫字母開頭(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("");

    }

}


查看完整回答
反對 回復 2023-06-14
  • 1 回答
  • 0 關注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號