From 6234d725e62ce9dc86a977c1eecf97daf5d7681f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sat, 4 Nov 2017 09:32:05 +0000 Subject: [PATCH] bug 61474, github #81: add shiftMergedRegions to BaseRowColShifter interface git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814264 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/helpers/BaseRowColShifter.java | 17 ++++++++++++ .../ss/usermodel/helpers/ColumnShifter.java | 26 ++----------------- .../poi/ss/usermodel/helpers/RowShifter.java | 1 + 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java index f926729515..f0bf7ab21e 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java @@ -25,6 +25,8 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Internal; +import java.util.List; + /** * Class for code common to {@link RowShifter} and {@link ColumnShifter} * Helper for shifting rows up or down and columns left and right @@ -44,7 +46,22 @@ public abstract class BaseRowColShifter { */ public abstract void updateFormulas(FormulaShifter formulaShifter); + /** + * Shifts, grows, or shrinks the merged regions due to a row shift + * ({@link RowShifter}) or column shift ({@link ColumnShifter}). + * Merged regions that are completely overlaid by shifting will be deleted. + * + * @param start the first row or column to be shifted + * @param end the last row or column to be shifted + * @param n the number of rows or columns to shift + * @return a list of affected merged regions, excluding contain deleted ones + */ + public abstract List shiftMergedRegions(int start, int end, int n); + /** + * Update conditional formatting + * @param formulaShifter + */ public abstract void updateConditionalFormatting(FormulaShifter formulaShifter); /** diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java index 444039a41b..a4d2508b66 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Beta; @@ -50,8 +49,10 @@ public abstract class ColumnShifter extends BaseRowColShifter { * @param endColumn the column to end shifting * @param n the number of columns to shift * @return an array of affected merged regions, doesn't contain deleted ones + * @since POI 4.0.0 */ // Keep this code in sync with {@link RowShifter#shiftMergedRegions} + @Override public List shiftMergedRegions(int startColumn, int endColumn, int n) { List shiftedRegions = new ArrayList<>(); Set removedIndices = new HashSet<>(); @@ -118,27 +119,4 @@ public abstract class ColumnShifter extends BaseRowColShifter { // if the merged-region and the overwritten area intersect, we need to remove it return merged.intersects(overwrite); } - - /** - * Updated named ranges - */ - public abstract void updateNamedRanges(FormulaShifter formulaShifter); - - /** - * Update formulas. - */ - public abstract void updateFormulas(FormulaShifter formulaShifter); - - - public abstract void updateConditionalFormatting(FormulaShifter formulaShifter); - - /** - * Shift the Hyperlink anchors (not the hyperlink text, even if the hyperlink - * is of type LINK_DOCUMENT and refers to a cell that was shifted). Hyperlinks - * do not track the content they point to. - * - * @param formulaShifter the formula shifting policy - */ - public abstract void updateHyperlinks(FormulaShifter formulaShifter); - } diff --git a/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java b/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java index d0ac13d7f2..4597bd1976 100644 --- a/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java +++ b/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java @@ -49,6 +49,7 @@ public abstract class RowShifter extends BaseRowColShifter { * @return an array of affected merged regions, doesn't contain deleted ones */ // Keep this code in sync with {@link ColumnShifter#shiftMergedRegions} + @Override public List shiftMergedRegions(int startRow, int endRow, int n) { List shiftedRegions = new ArrayList<>(); Set removedIndices = new HashSet<>(); -- 2.39.5