poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1814256 - in /poi/trunk/src: java/org/apache/poi/hssf/record/aggregates/ java/org/apache/poi/hssf/usermodel/helpers/ java/org/apache/poi/ss/usermodel/helpers/ ooxml/java/org/apache/poi/xssf/usermodel/helpers/
Date Sat, 04 Nov 2017 07:17:44 GMT
Author: onealj
Date: Sat Nov  4 07:17:44 2017
New Revision: 1814256

URL: http://svn.apache.org/viewvc?rev=1814256&view=rev
Log:
bug 61474, github #81: add ColumnShifter interface; deduplicate some code in RowShifter, CFRecordsAggregate

Added:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java
      - copied, changed from r1814255, poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java
      - copied, changed from r1814255, poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java
      - copied, changed from r1814255, poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java
      - copied, changed from r1814255, poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java
      - copied, changed from r1814255, poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java?rev=1814256&r1=1814255&r2=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java Sat Nov  4 07:17:44 2017
@@ -29,9 +29,8 @@ import org.apache.poi.hssf.record.CFRule
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.ss.formula.FormulaShifter;
-import org.apache.poi.ss.formula.ptg.AreaErrPtg;
-import org.apache.poi.ss.formula.ptg.AreaPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.helpers.BaseRowColShifter;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -223,7 +222,7 @@ public final class CFRecordsAggregate ex
         boolean changed = false;
         List<CellRangeAddress> temp = new ArrayList<>();
         for (CellRangeAddress craOld : cellRanges) {
-            CellRangeAddress craNew = shiftRange(shifter, craOld, currentExternSheetIx);
+            CellRangeAddress craNew = BaseRowColShifter.shiftRange(shifter, craOld, currentExternSheetIx);
             if (craNew == null) {
                 changed = true;
                 continue;
@@ -264,23 +263,4 @@ public final class CFRecordsAggregate ex
         }
         return true;
     }
-
-    private static CellRangeAddress shiftRange(FormulaShifter shifter, CellRangeAddress cra, int currentExternSheetIx) {
-        // FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
-        AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
-        Ptg[] ptgs = { aptg, };
-
-        if (!shifter.adjustFormula(ptgs, currentExternSheetIx)) {
-            return cra;
-        }
-        Ptg ptg0 = ptgs[0];
-        if (ptg0 instanceof AreaPtg) {
-            AreaPtg bptg = (AreaPtg) ptg0;
-            return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
-        }
-        if (ptg0 instanceof AreaErrPtg) {
-            return null;
-        }
-        throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
-    }
 }

Copied: poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java (from r1814255, poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java?p2=poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java&p1=poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java&r1=1814255&r2=1814256&rev=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFColumnShifter.java Sat Nov  4 07:17:44 2017
@@ -20,29 +20,29 @@ package org.apache.poi.hssf.usermodel.he
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.ss.formula.FormulaShifter;
 import org.apache.poi.ss.formula.eval.NotImplementedException;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.helpers.RowShifter;
-import org.apache.poi.util.Internal;
+import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
+import org.apache.poi.util.Beta;
 import org.apache.poi.util.NotImplemented;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
 /**
- * Helper for shifting rows up or down
- * 
- * When possible, code should be implemented in the RowShifter abstract class to avoid duplication with {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
+ * Helper for shifting columns up or down
  */
-public final class HSSFRowShifter extends RowShifter {
-    private static final POILogger logger = POILogFactory.getLogger(HSSFRowShifter.class);
+// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
+// {@link org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter}
+@Beta
+public final class HSSFColumnShifter extends ColumnShifter {
+    private static final POILogger logger = POILogFactory.getLogger(HSSFColumnShifter.class);
 
-    public HSSFRowShifter(HSSFSheet sh) {
+    public HSSFColumnShifter(HSSFSheet sh) {
         super(sh);
     }
 
     @Override
     @NotImplemented
     public void updateNamedRanges(FormulaShifter formulaShifter) {
-        throw new NotImplementedException("HSSFRowShifter.updateNamedRanges");
+        throw new NotImplementedException("HSSFColumnShifter.updateNamedRanges");
     }
 
     @Override
@@ -52,13 +52,6 @@ public final class HSSFRowShifter extend
     }
 
     @Override
-    @Internal
-    @NotImplemented
-    public void updateRowFormulas(Row row, FormulaShifter formulaShifter) {
-        throw new NotImplementedException("updateRowFormulas");
-    }
-
-    @Override
     @NotImplemented
     public void updateConditionalFormatting(FormulaShifter formulaShifter) {
         throw new NotImplementedException("updateConditionalFormatting");

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java?rev=1814256&r1=1814255&r2=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/helpers/HSSFRowShifter.java Sat Nov  4 07:17:44 2017
@@ -29,9 +29,9 @@ import org.apache.poi.util.POILogger;
 
 /**
  * Helper for shifting rows up or down
- * 
- * When possible, code should be implemented in the RowShifter abstract class to avoid duplication with {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
  */
+// non-Javadoc: When possible, code should be implemented in the RowShifter abstract class to avoid duplication with
+// {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
 public final class HSSFRowShifter extends RowShifter {
     private static final POILogger logger = POILogFactory.getLogger(HSSFRowShifter.class);
 

Copied: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java (from r1814255, poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java?p2=poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java&p1=poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java&r1=1814255&r2=1814256&rev=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/BaseRowColShifter.java Sat Nov  4 07:17:44 2017
@@ -17,128 +17,38 @@
 
 package org.apache.poi.ss.usermodel.helpers;
 
-import java.util.ArrayList;
-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.Row;
-import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.formula.ptg.AreaErrPtg;
+import org.apache.poi.ss.formula.ptg.AreaPtg;
+import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Internal;
 
 /**
- * Helper for shifting rows up or down
- * 
- * This abstract class exists to consolidate duplicated code between XSSFRowShifter and HSSFRowShifter (currently methods sprinkled throughout HSSFSheet)
+ * Class for code common to {@link RowShifter} and {@link ColumnShifter}
+ * Helper for shifting rows up or down and columns left and right
  */
-public abstract class RowShifter {
-    protected final Sheet sheet;
+@Internal
+public abstract class BaseRowColShifter {
 
-    public RowShifter(Sheet sh) {
-        sheet = sh;
-    }
+    public static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
+        // FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
+        AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
+        Ptg[] ptgs = { aptg, };
 
-    /**
-     * Shifts, grows, or shrinks the merged regions due to a row shift.
-     * Merged regions that are completely overlaid by shifting will be deleted.
-     *
-     * @param startRow the row to start shifting
-     * @param endRow   the row to end shifting
-     * @param n        the number of rows to shift
-     * @return an array of affected merged regions, doesn't contain deleted ones
-     */
-    public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int n) {
-        List<CellRangeAddress> shiftedRegions = new ArrayList<>();
-        Set<Integer> removedIndices = new HashSet<>();
-        //move merged regions completely if they fall within the new region boundaries when they are shifted
-        int size = sheet.getNumMergedRegions();
-        for (int i = 0; i < size; i++) {
-            CellRangeAddress merged = sheet.getMergedRegion(i);
-
-            // remove merged region that are replaced by the shifting,
-            // i.e. where the area includes something in the overwritten area
-            if(removalNeeded(merged, startRow, endRow, n)) {
-                removedIndices.add(i);
-                continue;
-            }
-
-            boolean inStart = (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
-            boolean inEnd = (merged.getFirstRow() <= endRow || merged.getLastRow() <= endRow);
-
-            //don't check if it's not within the shifted area
-            if (!inStart || !inEnd) {
-                continue;
-            }
-
-            //only shift if the region outside the shifted rows is not merged too
-            if (!merged.containsRow(startRow - 1) && !merged.containsRow(endRow + 1)) {
-                merged.setFirstRow(merged.getFirstRow() + n);
-                merged.setLastRow(merged.getLastRow() + n);
-                //have to remove/add it back
-                shiftedRegions.add(merged);
-                removedIndices.add(i);
-            }
-        }
-        
-        if(!removedIndices.isEmpty()) {
-            sheet.removeMergedRegions(removedIndices);
+        if (!formulaShifter.adjustFormula(ptgs, currentExternSheetIx)) {
+            return cra;
         }
-
-        //read so it doesn't get shifted again
-        for (CellRangeAddress region : shiftedRegions) {
-            sheet.addMergedRegion(region);
+        Ptg ptg0 = ptgs[0];
+        if (ptg0 instanceof AreaPtg) {
+            AreaPtg bptg = (AreaPtg) ptg0;
+            return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
         }
-        return shiftedRegions;
-    }
-
-    private boolean removalNeeded(CellRangeAddress merged, int startRow, int endRow, int n) {
-        final int movedRows = endRow - startRow + 1;
-
-        // build a range of the rows that are overwritten, i.e. the target-area, but without
-        // rows that are moved along
-        final CellRangeAddress overwrite;
-        if(n > 0) {
-            // area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
-            overwrite = new CellRangeAddress(Math.max(endRow + 1, endRow + n - movedRows), endRow + n, 0, 0);
-        } else {
-            // area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
-            overwrite = new CellRangeAddress(startRow + n, Math.min(startRow - 1, startRow + n + movedRows), 0, 0);
+        if (ptg0 instanceof AreaErrPtg) {
+            return null;
         }
-
-        // if the merged-region and the overwritten area intersect, we need to remove it
-        return merged.intersects(overwrite);
+        throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
     }
 
-    /**
-     * Updated named ranges
-     */
-    public abstract void updateNamedRanges(FormulaShifter formulaShifter);
-
-    /**
-     * Update formulas.
-     */
-    public abstract void updateFormulas(FormulaShifter formulaShifter);
-
-    /**
-     * Update the formulas in specified row using the formula shifting policy specified by shifter
-     *
-     * @param row the row to update the formulas on
-     * @param formulaShifter the formula shifting policy
-     */
-    @Internal
-    public abstract void updateRowFormulas(Row row, 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);
-
 }

Copied: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java (from r1814255, poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java?p2=poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java&p1=poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java&r1=1814255&r2=1814256&rev=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/ColumnShifter.java Sat Nov  4 07:17:44 2017
@@ -23,33 +23,33 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.poi.ss.formula.FormulaShifter;
-import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.util.Internal;
+import org.apache.poi.util.Beta;
 
 /**
- * Helper for shifting rows up or down
- * 
- * This abstract class exists to consolidate duplicated code between XSSFRowShifter and HSSFRowShifter (currently methods sprinkled throughout HSSFSheet)
+ * Helper for shifting columns up or down
  */
-public abstract class RowShifter {
+// non-Javadoc: This abstract class exists to consolidate duplicated code between XSSFColumnShifter and HSSFColumnShifter
+// (currently methods sprinkled throughout HSSFSheet)
+@Beta
+public abstract class ColumnShifter extends BaseRowColShifter {
     protected final Sheet sheet;
 
-    public RowShifter(Sheet sh) {
+    public ColumnShifter(Sheet sh) {
         sheet = sh;
     }
 
     /**
-     * Shifts, grows, or shrinks the merged regions due to a row shift.
+     * Shifts, grows, or shrinks the merged regions due to a column shift.
      * Merged regions that are completely overlaid by shifting will be deleted.
      *
-     * @param startRow the row to start shifting
-     * @param endRow   the row to end shifting
-     * @param n        the number of rows to shift
+     * @param startColumn the column to start shifting
+     * @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
      */
-    public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int n) {
+    public List<CellRangeAddress> shiftMergedRegions(int startColumn, int endColumn, int n) {
         List<CellRangeAddress> shiftedRegions = new ArrayList<>();
         Set<Integer> removedIndices = new HashSet<>();
         //move merged regions completely if they fall within the new region boundaries when they are shifted
@@ -59,23 +59,23 @@ public abstract class RowShifter {
 
             // remove merged region that are replaced by the shifting,
             // i.e. where the area includes something in the overwritten area
-            if(removalNeeded(merged, startRow, endRow, n)) {
+            if(removalNeeded(merged, startColumn, endColumn, n)) {
                 removedIndices.add(i);
                 continue;
             }
 
-            boolean inStart = (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
-            boolean inEnd = (merged.getFirstRow() <= endRow || merged.getLastRow() <= endRow);
+            boolean inStart = (merged.getFirstColumn() >= startColumn || merged.getLastColumn() >= startColumn);
+            boolean inEnd = (merged.getFirstColumn() <= endColumn || merged.getLastColumn() <= endColumn);
 
             //don't check if it's not within the shifted area
             if (!inStart || !inEnd) {
                 continue;
             }
 
-            //only shift if the region outside the shifted rows is not merged too
-            if (!merged.containsRow(startRow - 1) && !merged.containsRow(endRow + 1)) {
-                merged.setFirstRow(merged.getFirstRow() + n);
-                merged.setLastRow(merged.getLastRow() + n);
+            //only shift if the region outside the shifted columns is not merged too
+            if (!merged.containsColumn(startColumn - 1) && !merged.containsColumn(endColumn + 1)) {
+                merged.setFirstColumn(merged.getFirstColumn() + n);
+                merged.setLastColumn(merged.getLastColumn() + n);
                 //have to remove/add it back
                 shiftedRegions.add(merged);
                 removedIndices.add(i);
@@ -93,18 +93,18 @@ public abstract class RowShifter {
         return shiftedRegions;
     }
 
-    private boolean removalNeeded(CellRangeAddress merged, int startRow, int endRow, int n) {
-        final int movedRows = endRow - startRow + 1;
+    private boolean removalNeeded(CellRangeAddress merged, int startColumn, int endColumn, int n) {
+        final int movedColumns = endColumn - startColumn + 1;
 
-        // build a range of the rows that are overwritten, i.e. the target-area, but without
-        // rows that are moved along
+        // build a range of the columns that are overwritten, i.e. the target-area, but without
+        // columns that are moved along
         final CellRangeAddress overwrite;
         if(n > 0) {
-            // area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
-            overwrite = new CellRangeAddress(Math.max(endRow + 1, endRow + n - movedRows), endRow + n, 0, 0);
+            // area is moved down => overwritten area is [endColumn + n - movedColumns, endColumn + n]
+            overwrite = new CellRangeAddress(Math.max(endColumn + 1, endColumn + n - movedColumns), endColumn + n, 0, 0);
         } else {
-            // area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
-            overwrite = new CellRangeAddress(startRow + n, Math.min(startRow - 1, startRow + n + movedRows), 0, 0);
+            // area is moved up => overwritten area is [startColumn + n, startColumn + n + movedColumns]
+            overwrite = new CellRangeAddress(startColumn + n, Math.min(startColumn - 1, startColumn + n + movedColumns), 0, 0);
         }
 
         // if the merged-region and the overwritten area intersect, we need to remove it
@@ -121,14 +121,6 @@ public abstract class RowShifter {
      */
     public abstract void updateFormulas(FormulaShifter formulaShifter);
 
-    /**
-     * Update the formulas in specified row using the formula shifting policy specified by shifter
-     *
-     * @param row the row to update the formulas on
-     * @param formulaShifter the formula shifting policy
-     */
-    @Internal
-    public abstract void updateRowFormulas(Row row, FormulaShifter formulaShifter);
 
     public abstract void updateConditionalFormatting(FormulaShifter formulaShifter);
     

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java?rev=1814256&r1=1814255&r2=1814256&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/helpers/RowShifter.java Sat Nov  4 07:17:44 2017
@@ -30,10 +30,12 @@ import org.apache.poi.util.Internal;
 
 /**
  * Helper for shifting rows up or down
- * 
- * This abstract class exists to consolidate duplicated code between XSSFRowShifter and HSSFRowShifter (currently methods sprinkled throughout HSSFSheet)
  */
-public abstract class RowShifter {
+// non-Javadoc: This abstract class exists to consolidate duplicated code between
+// {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter} and
+// {@link org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter}
+// (currently methods sprinkled throughout HSSFSheet)
+public abstract class RowShifter extends BaseRowColShifter {
     protected final Sheet sheet;
 
     public RowShifter(Sheet sh) {

Copied: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java (from r1814255, poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java?p2=poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java&p1=poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java&r1=1814255&r2=1814256&rev=1814256&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java Sat Nov  4 07:17:44 2017
@@ -17,231 +17,55 @@
 
 package org.apache.poi.xssf.usermodel.helpers;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.poi.ss.formula.FormulaParseException;
-import org.apache.poi.ss.formula.FormulaParser;
-import org.apache.poi.ss.formula.FormulaRenderer;
-import org.apache.poi.ss.formula.FormulaShifter;
-import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.ptg.AreaErrPtg;
-import org.apache.poi.ss.formula.ptg.AreaPtg;
-import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.helpers.RowShifter;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.util.Internal;
+import org.apache.poi.ss.formula.*;
+import org.apache.poi.ss.formula.eval.NotImplementedException;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
+import org.apache.poi.util.Beta;
+import org.apache.poi.util.NotImplemented;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFHyperlink;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
+import org.apache.poi.xssf.usermodel.*;
 
 /**
- * Helper for shifting rows up or down
- * 
- * When possible, code should be implemented in the RowShifter abstract class to avoid duplication with {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter}
+ * Helper for shifting columns up or down
  */
-public final class XSSFRowShifter extends RowShifter {
-    private static final POILogger logger = POILogFactory.getLogger(XSSFRowShifter.class);
+// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
+// {@link org.apache.poi.hssf.usermodel.helpers.HSSFColumnShifter}
+@Beta
+public final class XSSFColumnShifter extends ColumnShifter {
+    private static final POILogger logger = POILogFactory.getLogger(XSSFColumnShifter.class);
 
-    public XSSFRowShifter(XSSFSheet sh) {
+    public XSSFColumnShifter(XSSFSheet sh) {
         super(sh);
     }
 
     /**
      * Updated named ranges
      */
+    @NotImplemented
     @Override
     public void updateNamedRanges(FormulaShifter formulaShifter) {
-        Workbook wb = sheet.getWorkbook();
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
-        for (Name name : wb.getAllNames()) {
-            String formula = name.getRefersToFormula();
-            int sheetIndex = name.getSheetIndex();
-            final int rowIndex = -1; //don't care, named ranges are not allowed to include structured references
-
-            Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.NAMEDRANGE, sheetIndex, rowIndex);
-            if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-                name.setRefersToFormula(shiftedFmla);
-            }
-        }
+        throw new NotImplementedException("updateNamedRanges");
     }
 
     /**
      * Update formulas.
      */
+    @NotImplemented
     @Override
     public void updateFormulas(FormulaShifter formulaShifter) {
-        //update formulas on the parent sheet
-        updateSheetFormulas(sheet, formulaShifter);
-
-        //update formulas on other sheets
-        Workbook wb = sheet.getWorkbook();
-        for (Sheet sh : wb) {
-            if (sheet == sh) continue;
-            updateSheetFormulas(sh, formulaShifter);
-        }
-    }
-
-    private void updateSheetFormulas(Sheet sh, FormulaShifter formulashifter) {
-        for (Row r : sh) {
-            XSSFRow row = (XSSFRow) r;
-            updateRowFormulas(row, formulashifter);
-        }
-    }
-
-    /**
-     * Update the formulas in specified row using the formula shifting policy specified by shifter
-     *
-     * @param row the row to update the formulas on
-     * @param formulaShifter the formula shifting policy
-     */
-    @Internal
-    @Override
-    public void updateRowFormulas(Row row, FormulaShifter formulaShifter) {
-        XSSFSheet sheet = (XSSFSheet) row.getSheet();
-        for (Cell c : row) {
-            XSSFCell cell = (XSSFCell) c;
-
-            CTCell ctCell = cell.getCTCell();
-            if (ctCell.isSetF()) {
-                CTCellFormula f = ctCell.getF();
-                String formula = f.getStringValue();
-                if (formula.length() > 0) {
-                    String shiftedFormula = shiftFormula(row, formula, formulaShifter);
-                    if (shiftedFormula != null) {
-                        f.setStringValue(shiftedFormula);
-                        if(f.getT() == STCellFormulaType.SHARED){
-                            int si = (int)f.getSi();
-                            CTCellFormula sf = sheet.getSharedFormula(si);
-                            sf.setStringValue(shiftedFormula);
-                            updateRefInCTCellFormula(row, formulaShifter, sf);
-                        }
-                    }
-
-                }
-
-                //Range of cells which the formula applies to.
-                updateRefInCTCellFormula(row, formulaShifter, f);
-            }
-
-        }
+        throw new NotImplementedException("updateFormulas");
     }
 
-    private void updateRefInCTCellFormula(Row row, FormulaShifter formulaShifter, CTCellFormula f) {
-        if (f.isSetRef()) { //Range of cells which the formula applies to.
-            String ref = f.getRef();
-            String shiftedRef = shiftFormula(row, ref, formulaShifter);
-            if (shiftedRef != null) f.setRef(shiftedRef);
-        }
-    }
-
-    /**
-     * Shift a formula using the supplied FormulaShifter
-     *
-     * @param row     the row of the cell this formula belongs to. Used to get a reference to the parent workbook.
-     * @param formula the formula to shift
-     * @param formulaShifter the FormulaShifter object that operates on the parsed formula tokens
-     * @return the shifted formula if the formula was changed,
-     *         <code>null</code> if the formula wasn't modified
-     */
-    private static String shiftFormula(Row row, String formula, FormulaShifter formulaShifter) {
-        Sheet sheet = row.getSheet();
-        Workbook wb = sheet.getWorkbook();
-        int sheetIndex = wb.getSheetIndex(sheet);
-        final int rowIndex = row.getRowNum();
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
-        
-        try {
-            Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex);
-            String shiftedFmla = null;
-            if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-            }
-            return shiftedFmla;
-        } catch (FormulaParseException fpe) {
-            // Log, but don't change, rather than breaking
-            logger.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe);
-            return formula;
-        }
+    private void updateSheetFormulas(Sheet sh, FormulaShifter formulaShifter) {
+        throw new NotImplementedException("updateSheetFormulas");
     }
 
+    @NotImplemented
     @Override
     public void updateConditionalFormatting(FormulaShifter formulaShifter) {
-        XSSFSheet xsheet = (XSSFSheet) sheet;
-        XSSFWorkbook wb = xsheet.getWorkbook();
-        int sheetIndex = wb.getSheetIndex(sheet);
-        final int rowIndex = -1; //don't care, structured references not allowed in conditional formatting
-
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
-        CTWorksheet ctWorksheet = xsheet.getCTWorksheet();
-        CTConditionalFormatting[] conditionalFormattingArray = ctWorksheet.getConditionalFormattingArray();
-        // iterate backwards due to possible calls to ctWorksheet.removeConditionalFormatting(j)
-        for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
-            CTConditionalFormatting cf = conditionalFormattingArray[j];
-
-            ArrayList<CellRangeAddress> cellRanges = new ArrayList<>();
-            for (Object stRef : cf.getSqref()) {
-                String[] regions = stRef.toString().split(" ");
-                for (String region : regions) {
-                    cellRanges.add(CellRangeAddress.valueOf(region));
-                }
-            }
-
-            boolean changed = false;
-            List<CellRangeAddress> temp = new ArrayList<>();
-            for (CellRangeAddress craOld : cellRanges) {
-                CellRangeAddress craNew = shiftRange(formulaShifter, craOld, sheetIndex);
-                if (craNew == null) {
-                    changed = true;
-                    continue;
-                }
-                temp.add(craNew);
-                if (craNew != craOld) {
-                    changed = true;
-                }
-            }
-
-            if (changed) {
-                int nRanges = temp.size();
-                if (nRanges == 0) {
-                    ctWorksheet.removeConditionalFormatting(j);
-                    continue;
-                }
-                List<String> refs = new ArrayList<>();
-                for(CellRangeAddress a : temp) refs.add(a.formatAsString());
-                cf.setSqref(refs);
-            }
-
-            for(CTCfRule cfRule : cf.getCfRuleArray()){
-                String[] formulaArray = cfRule.getFormulaArray();
-                for (int i = 0; i < formulaArray.length; i++) {
-                    String formula = formulaArray[i];
-                    Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex);
-                    if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                        String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-                        cfRule.setFormulaArray(i, shiftedFmla);
-                    }
-                }
-            }
-        }
+        throw new NotImplementedException("updateConditionalformatting");
     }
     
     /**
@@ -253,40 +77,7 @@ public final class XSSFRowShifter extend
      */
     @Override
     public void updateHyperlinks(FormulaShifter formulaShifter) {
-        int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
-        List<? extends Hyperlink> hyperlinkList = sheet.getHyperlinkList();
-        
-        for (Hyperlink hyperlink : hyperlinkList) {
-            XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
-            String cellRef = xhyperlink.getCellRef();
-            CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
-            CellRangeAddress shiftedRange = shiftRange(formulaShifter, cra, sheetIndex);
-            if (shiftedRange != null && shiftedRange != cra) {
-                // shiftedRange should not be null. If shiftedRange is null, that means
-                // that a hyperlink wasn't deleted at the beginning of shiftRows when
-                // identifying rows that should be removed because they will be overwritten
-                xhyperlink.setCellReference(shiftedRange.formatAsString());
-            }
-        }
-    }
-
-    private static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
-        // FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
-        AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
-        Ptg[] ptgs = { aptg, };
-
-        if (!formulaShifter.adjustFormula(ptgs, currentExternSheetIx)) {
-            return cra;
-        }
-        Ptg ptg0 = ptgs[0];
-        if (ptg0 instanceof AreaPtg) {
-            AreaPtg bptg = (AreaPtg) ptg0;
-            return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
-        }
-        if (ptg0 instanceof AreaErrPtg) {
-            return null;
-        }
-        throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
+        XSSFRowColShifter.updateHyperlinks(sheet, formulaShifter);
     }
 
 }

Copied: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java (from r1814255, poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java?p2=poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java&p1=poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java&r1=1814255&r2=1814256&rev=1814256&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowColShifter.java Sat Nov  4 07:17:44 2017
@@ -17,245 +17,30 @@
 
 package org.apache.poi.xssf.usermodel.helpers;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.poi.ss.formula.FormulaParseException;
-import org.apache.poi.ss.formula.FormulaParser;
-import org.apache.poi.ss.formula.FormulaRenderer;
-import org.apache.poi.ss.formula.FormulaShifter;
-import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.ptg.AreaErrPtg;
-import org.apache.poi.ss.formula.ptg.AreaPtg;
-import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.helpers.RowShifter;
+import org.apache.poi.ss.formula.*;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.helpers.BaseRowColShifter;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFHyperlink;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
+import org.apache.poi.xssf.usermodel.*;
+
+import java.util.List;
 
 /**
- * Helper for shifting rows up or down
- * 
- * When possible, code should be implemented in the RowShifter abstract class to avoid duplication with {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter}
+ * Class for code common to {@link XSSFRowShifter} and {@link XSSFColumnShifter}
  */
-public final class XSSFRowShifter extends RowShifter {
-    private static final POILogger logger = POILogFactory.getLogger(XSSFRowShifter.class);
-
-    public XSSFRowShifter(XSSFSheet sh) {
-        super(sh);
-    }
-
-    /**
-     * Updated named ranges
-     */
-    @Override
-    public void updateNamedRanges(FormulaShifter formulaShifter) {
-        Workbook wb = sheet.getWorkbook();
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
-        for (Name name : wb.getAllNames()) {
-            String formula = name.getRefersToFormula();
-            int sheetIndex = name.getSheetIndex();
-            final int rowIndex = -1; //don't care, named ranges are not allowed to include structured references
+@Internal
+/*private*/ final class XSSFRowColShifter extends BaseRowColShifter {
+    private static final POILogger logger = POILogFactory.getLogger(XSSFRowColShifter.class);
 
-            Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.NAMEDRANGE, sheetIndex, rowIndex);
-            if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-                name.setRefersToFormula(shiftedFmla);
-            }
-        }
-    }
-
-    /**
-     * Update formulas.
-     */
-    @Override
-    public void updateFormulas(FormulaShifter formulaShifter) {
-        //update formulas on the parent sheet
-        updateSheetFormulas(sheet, formulaShifter);
-
-        //update formulas on other sheets
-        Workbook wb = sheet.getWorkbook();
-        for (Sheet sh : wb) {
-            if (sheet == sh) continue;
-            updateSheetFormulas(sh, formulaShifter);
-        }
-    }
-
-    private void updateSheetFormulas(Sheet sh, FormulaShifter formulashifter) {
-        for (Row r : sh) {
-            XSSFRow row = (XSSFRow) r;
-            updateRowFormulas(row, formulashifter);
-        }
-    }
-
-    /**
-     * Update the formulas in specified row using the formula shifting policy specified by shifter
-     *
-     * @param row the row to update the formulas on
-     * @param formulaShifter the formula shifting policy
-     */
-    @Internal
-    @Override
-    public void updateRowFormulas(Row row, FormulaShifter formulaShifter) {
-        XSSFSheet sheet = (XSSFSheet) row.getSheet();
-        for (Cell c : row) {
-            XSSFCell cell = (XSSFCell) c;
-
-            CTCell ctCell = cell.getCTCell();
-            if (ctCell.isSetF()) {
-                CTCellFormula f = ctCell.getF();
-                String formula = f.getStringValue();
-                if (formula.length() > 0) {
-                    String shiftedFormula = shiftFormula(row, formula, formulaShifter);
-                    if (shiftedFormula != null) {
-                        f.setStringValue(shiftedFormula);
-                        if(f.getT() == STCellFormulaType.SHARED){
-                            int si = (int)f.getSi();
-                            CTCellFormula sf = sheet.getSharedFormula(si);
-                            sf.setStringValue(shiftedFormula);
-                            updateRefInCTCellFormula(row, formulaShifter, sf);
-                        }
-                    }
-
-                }
-
-                //Range of cells which the formula applies to.
-                updateRefInCTCellFormula(row, formulaShifter, f);
-            }
-
-        }
-    }
+    private XSSFRowColShifter() { /*no instances for static classes*/}
 
-    private void updateRefInCTCellFormula(Row row, FormulaShifter formulaShifter, CTCellFormula f) {
-        if (f.isSetRef()) { //Range of cells which the formula applies to.
-            String ref = f.getRef();
-            String shiftedRef = shiftFormula(row, ref, formulaShifter);
-            if (shiftedRef != null) f.setRef(shiftedRef);
-        }
-    }
-
-    /**
-     * Shift a formula using the supplied FormulaShifter
-     *
-     * @param row     the row of the cell this formula belongs to. Used to get a reference to the parent workbook.
-     * @param formula the formula to shift
-     * @param formulaShifter the FormulaShifter object that operates on the parsed formula tokens
-     * @return the shifted formula if the formula was changed,
-     *         <code>null</code> if the formula wasn't modified
-     */
-    private static String shiftFormula(Row row, String formula, FormulaShifter formulaShifter) {
-        Sheet sheet = row.getSheet();
-        Workbook wb = sheet.getWorkbook();
-        int sheetIndex = wb.getSheetIndex(sheet);
-        final int rowIndex = row.getRowNum();
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
-        
-        try {
-            Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex);
-            String shiftedFmla = null;
-            if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-            }
-            return shiftedFmla;
-        } catch (FormulaParseException fpe) {
-            // Log, but don't change, rather than breaking
-            logger.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe);
-            return formula;
-        }
-    }
-
-    @Override
-    public void updateConditionalFormatting(FormulaShifter formulaShifter) {
-        XSSFSheet xsheet = (XSSFSheet) sheet;
-        XSSFWorkbook wb = xsheet.getWorkbook();
-        int sheetIndex = wb.getSheetIndex(sheet);
-        final int rowIndex = -1; //don't care, structured references not allowed in conditional formatting
-
-        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
-        CTWorksheet ctWorksheet = xsheet.getCTWorksheet();
-        CTConditionalFormatting[] conditionalFormattingArray = ctWorksheet.getConditionalFormattingArray();
-        // iterate backwards due to possible calls to ctWorksheet.removeConditionalFormatting(j)
-        for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
-            CTConditionalFormatting cf = conditionalFormattingArray[j];
-
-            ArrayList<CellRangeAddress> cellRanges = new ArrayList<>();
-            for (Object stRef : cf.getSqref()) {
-                String[] regions = stRef.toString().split(" ");
-                for (String region : regions) {
-                    cellRanges.add(CellRangeAddress.valueOf(region));
-                }
-            }
-
-            boolean changed = false;
-            List<CellRangeAddress> temp = new ArrayList<>();
-            for (CellRangeAddress craOld : cellRanges) {
-                CellRangeAddress craNew = shiftRange(formulaShifter, craOld, sheetIndex);
-                if (craNew == null) {
-                    changed = true;
-                    continue;
-                }
-                temp.add(craNew);
-                if (craNew != craOld) {
-                    changed = true;
-                }
-            }
-
-            if (changed) {
-                int nRanges = temp.size();
-                if (nRanges == 0) {
-                    ctWorksheet.removeConditionalFormatting(j);
-                    continue;
-                }
-                List<String> refs = new ArrayList<>();
-                for(CellRangeAddress a : temp) refs.add(a.formatAsString());
-                cf.setSqref(refs);
-            }
-
-            for(CTCfRule cfRule : cf.getCfRuleArray()){
-                String[] formulaArray = cfRule.getFormulaArray();
-                for (int i = 0; i < formulaArray.length; i++) {
-                    String formula = formulaArray[i];
-                    Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex);
-                    if (formulaShifter.adjustFormula(ptgs, sheetIndex)) {
-                        String shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs);
-                        cfRule.setFormulaArray(i, shiftedFmla);
-                    }
-                }
-            }
-        }
-    }
-    
-    /**
-     * 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
-     */
-    @Override
-    public void updateHyperlinks(FormulaShifter formulaShifter) {
+    /*package*/ static void updateHyperlinks(Sheet sheet, FormulaShifter formulaShifter) {
         int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
         List<? extends Hyperlink> hyperlinkList = sheet.getHyperlinkList();
-        
+
         for (Hyperlink hyperlink : hyperlinkList) {
             XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
             String cellRef = xhyperlink.getCellRef();
@@ -270,23 +55,5 @@ public final class XSSFRowShifter extend
         }
     }
 
-    private static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
-        // FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
-        AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
-        Ptg[] ptgs = { aptg, };
-
-        if (!formulaShifter.adjustFormula(ptgs, currentExternSheetIx)) {
-            return cra;
-        }
-        Ptg ptg0 = ptgs[0];
-        if (ptg0 instanceof AreaPtg) {
-            AreaPtg bptg = (AreaPtg) ptg0;
-            return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
-        }
-        if (ptg0 instanceof AreaErrPtg) {
-            return null;
-        }
-        throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
-    }
 
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java?rev=1814256&r1=1814255&r2=1814256&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java Sat Nov  4 07:17:44 2017
@@ -25,11 +25,8 @@ import org.apache.poi.ss.formula.Formula
 import org.apache.poi.ss.formula.FormulaRenderer;
 import org.apache.poi.ss.formula.FormulaShifter;
 import org.apache.poi.ss.formula.FormulaType;
-import org.apache.poi.ss.formula.ptg.AreaErrPtg;
-import org.apache.poi.ss.formula.ptg.AreaPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Hyperlink;
 import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
@@ -41,7 +38,6 @@ import org.apache.poi.util.POILogFactory
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFHyperlink;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -54,9 +50,9 @@ import org.openxmlformats.schemas.spread
 
 /**
  * Helper for shifting rows up or down
- * 
- * When possible, code should be implemented in the RowShifter abstract class to avoid duplication with {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter}
  */
+// non-Javadoc: When possible, code should be implemented in the RowShifter abstract class to avoid duplication with
+// {@link org.apache.poi.hssf.usermodel.helpers.HSSFRowShifter}
 public final class XSSFRowShifter extends RowShifter {
     private static final POILogger logger = POILogFactory.getLogger(XSSFRowShifter.class);
 
@@ -253,40 +249,8 @@ public final class XSSFRowShifter extend
      */
     @Override
     public void updateHyperlinks(FormulaShifter formulaShifter) {
-        int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
-        List<? extends Hyperlink> hyperlinkList = sheet.getHyperlinkList();
-        
-        for (Hyperlink hyperlink : hyperlinkList) {
-            XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
-            String cellRef = xhyperlink.getCellRef();
-            CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
-            CellRangeAddress shiftedRange = shiftRange(formulaShifter, cra, sheetIndex);
-            if (shiftedRange != null && shiftedRange != cra) {
-                // shiftedRange should not be null. If shiftedRange is null, that means
-                // that a hyperlink wasn't deleted at the beginning of shiftRows when
-                // identifying rows that should be removed because they will be overwritten
-                xhyperlink.setCellReference(shiftedRange.formatAsString());
-            }
-        }
+        XSSFRowColShifter.updateHyperlinks(sheet, formulaShifter);
     }
 
-    private static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
-        // FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
-        AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
-        Ptg[] ptgs = { aptg, };
-
-        if (!formulaShifter.adjustFormula(ptgs, currentExternSheetIx)) {
-            return cra;
-        }
-        Ptg ptg0 = ptgs[0];
-        if (ptg0 instanceof AreaPtg) {
-            AreaPtg bptg = (AreaPtg) ptg0;
-            return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
-        }
-        if (ptg0 instanceof AreaErrPtg) {
-            return null;
-        }
-        throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
-    }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message