簡體   English   中英

如何從合並的Excel單元獲取價值?

[英]How to get value from the merged excel cell?

在此處輸入圖片說明

需要幫助以從“標價總計”獲取合並的單元格值。 如上圖所示,其合並后的單元格從第13行到第18行開始。 我正在使用下面的代碼來獲取值,但仍將其獲取為null。

CellRangeAddress mergedCell = new CellRangeAddress(12, 17, 9, 9);
int rowNum = mergedCell.getFirstRow();
int lastRow = mergedCell.getLastRow();
int colIndex = mergedCell.getFirstColumn();
for (int rowCounter = rowNum; rowCounter < lastRow; rowCounter++) {
            Cell cell2Update = sheet.getRow(rowCounter).getCell(colIndex);
            cell2Update.setCellType(Cell.CELL_TYPE_NUMERIC);
            CellValue c = evaluator.evaluate(cell2Update);
            if (null != c) {
                Double lisPrice= c.getNumberValue();
                if (lisPrice> 0) {
                    spreadheetResultData.setListPricetotal(df.format(lisPrice));
                }
            }
        }

請幫助我以獲得合並的單元格值。

如評論中所述,僅指最左上角的單元格,例如,如果合並范圍A2到C4,則= A2的公式將返回合並的單元格的內容,這與宏相同。

  1. 選擇合並的單元格區域;
  2. 在Excel中查看它所引用的單元格(紅色箭頭);
  3. 引用此單元格;

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM