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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

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

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

浮云間 2023-06-14 15:00:13
我的目標(biāo)是遍歷一個(gè)已有的 2 列 Excel 電子表格。一個(gè)稱(chēng)為制造商,另一個(gè)稱(chēng)為 DNC 或請(qǐng)勿聯(lián)系。我想遍歷我擁有的制造商列表,并將那些不應(yīng)聯(lián)系的標(biāo)記為紅色,并在制造商名稱(chēng)列表旁邊的相鄰空白欄中標(biāo)記一些為什么無(wú)法聯(lián)系他們的注釋。我在下面附上了我的代碼。我將每個(gè)制造商對(duì)象的字段存儲(chǔ)在一個(gè)名為“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 回答

?
江戶(hù)川亂折騰

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊

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

  2. 您應(yīng)該使用 的結(jié)果遍歷行rowIterator。您不需要另一個(gè)迭代器。

  3. 局部變量不應(yīng)該以大寫(xiě)字母開(kāi)頭(DNC_Reason-更好的名字是dncReasonCell

假設(shè)制造商單元格已填充的示例代碼(getStringValue()可能會(huì)導(dǎo)致NullPointerException未給出適當(dāng)?shù)闹担?,樣式變量已初始化并且您有一個(gè)不可聯(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("");

    }

}


查看完整回答
反對(duì) 回復(fù) 2023-06-14
  • 1 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)