private void correctNameRange(final Sheet sheet, final RecordOperation recordOperation) {

        if(recordOperation.isNotExecuteRecordOperation()) {
            return;
        }

        final Workbook workbook = sheet.getWorkbook();
        final int numName = workbook.getNumberOfNames();
        if(numName == 0) {
            return;
        }

        // 操作をしていないセルの範囲の取得
        final CellRangeAddress notOperateRange = new CellRangeAddress(
                recordOperation.getTopLeftPoisitoin().y,
                recordOperation.getBottomRightPosition().y - recordOperation.getCountInsertRecord(),
                recordOperation.getTopLeftPoisitoin().x,
                recordOperation.getBottomRightPosition().x
                );

        for(int i=0; i < numName; i++) {
            final Name name = workbook.getNameAt(i);

            if(name.isDeleted() || name.isFunctionName()) {
                // 削除されている場合、関数の場合はスキップ
                continue;
            }

            if(!sheet.getSheetName().equals(name.getSheetName())) {
                // 自身のシートでない名前は、修正しない。
                continue;
            }

            AreaReference areaRef = new AreaReference(name.getRefersToFormula(), POIUtils.getVersion(sheet));
            CellReference firstCellRef = areaRef.getFirstCell();
            CellReference lastCellRef = areaRef.getLastCell();

            if(notOperateRange.isInRange(firstCellRef.getRow(), firstCellRef.getCol())) {
                // 自身のセルの範囲の場合は、行の範囲を広げる。

                lastCellRef= new CellReference(
                        lastCellRef.getSheetName(),
                        recordOperation.getBottomRightPosition().y, lastCellRef.getCol(),
                        lastCellRef.isRowAbsolute(), lastCellRef.isColAbsolute());
                areaRef = new AreaReference(firstCellRef, lastCellRef, sheet.getWorkbook().getSpreadsheetVersion());

                // 修正した範囲を再設定する
                name.setRefersToFormula(areaRef.formatAsString());

            } else if(notOperateRange.getLastRow() < firstCellRef.getRow()) {
                /*
                 * 名前の定義の場合、自身のセルの範囲より下方にあるセルの範囲の場合、
                 * 自動的に修正されるため、修正は必要なし。
                 */

            }

        }

    }
private void correctNameRange ( final Sheet sheet , final RecordOperation recordOperation ) { if ( recordOperation . isNotExecuteRecordOperation ( ) ) { return ; } final Workbook workbook = sheet . getWorkbook ( ) ; final int numName = workbook . getNumberOfNames ( ) ; if ( numName == 0 ) { return ; } final CellRangeAddress notOperateRange = new CellRangeAddress ( recordOperation . getTopLeftPoisitoin ( ) . y , recordOperation . getBottomRightPosition ( ) . y - recordOperation . getCountInsertRecord ( ) , recordOperation . getTopLeftPoisitoin ( ) . x , recordOperation . getBottomRightPosition ( ) . x ) ; for ( int i = 0 ; i < numName ; i ++ ) { final Name name = workbook . getNameAt ( i ) ; if ( name . isDeleted ( ) || name . isFunctionName ( ) ) { continue ; } if ( ! sheet . getSheetName ( ) . equals ( name . getSheetName ( ) ) ) { continue ; } AreaReference areaRef = new AreaReference ( name . getRefersToFormula ( ) , POIUtils . getVersion ( sheet ) ) ; CellReference firstCellRef = areaRef . getFirstCell ( ) ; CellReference lastCellRef = areaRef . getLastCell ( ) ; if ( notOperateRange . isInRange ( firstCellRef . getRow ( ) , firstCellRef . getCol ( ) ) ) { lastCellRef = new CellReference ( lastCellRef . getSheetName ( ) , recordOperation . getBottomRightPosition ( ) . y , lastCellRef . getCol ( ) , lastCellRef . isRowAbsolute ( ) , lastCellRef . isColAbsolute ( ) ) ; areaRef = new AreaReference ( firstCellRef , lastCellRef , sheet . getWorkbook ( ) . getSpreadsheetVersion ( ) ) ; name . setRefersToFormula ( areaRef . formatAsString ( ) ) ; } else if ( notOperateRange . getLastRow ( ) < firstCellRef . getRow ( ) ) { } } }
名前の定義の範囲を修正する。
@param sheet
@param recordOperation