bug 61474, github #81: pull up methods from RowShifter to BaseRowColShifter, since both row and column shifting should be able to shift formulas, comments, merged regions, conditional formatting, etc; add @since decorators for new *ColumnShifter and *RowColShifter classes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec8b13c3a8
commit
6fcacf21f3
@ -28,6 +28,8 @@ import org.apache.poi.util.POILogger;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for shifting columns up or down
|
* Helper for shifting columns up or down
|
||||||
|
*
|
||||||
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
|
// 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}
|
// {@link org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter}
|
||||||
|
@ -28,10 +28,34 @@ import org.apache.poi.util.Internal;
|
|||||||
/**
|
/**
|
||||||
* Class for code common to {@link RowShifter} and {@link ColumnShifter}
|
* Class for code common to {@link RowShifter} and {@link ColumnShifter}
|
||||||
* Helper for shifting rows up or down and columns left and right
|
* Helper for shifting rows up or down and columns left and right
|
||||||
|
*
|
||||||
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public abstract class BaseRowColShifter {
|
public abstract class BaseRowColShifter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updated named ranges
|
||||||
|
*/
|
||||||
|
protected abstract void updateNamedRanges(FormulaShifter formulaShifter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update formulas.
|
||||||
|
*/
|
||||||
|
protected 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);
|
||||||
|
|
||||||
public static CellRangeAddress shiftRange(FormulaShifter formulaShifter, CellRangeAddress cra, int currentExternSheetIx) {
|
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
|
// 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);
|
AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
|
||||||
|
@ -29,6 +29,8 @@ import org.apache.poi.util.Beta;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for shifting columns up or down
|
* Helper for shifting columns up or down
|
||||||
|
*
|
||||||
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
// non-Javadoc: This abstract class exists to consolidate duplicated code between XSSFColumnShifter and HSSFColumnShifter
|
// non-Javadoc: This abstract class exists to consolidate duplicated code between XSSFColumnShifter and HSSFColumnShifter
|
||||||
// (currently methods sprinkled throughout HSSFSheet)
|
// (currently methods sprinkled throughout HSSFSheet)
|
||||||
|
@ -22,11 +22,8 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.util.Internal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for shifting rows up or down
|
* Helper for shifting rows up or down
|
||||||
@ -118,35 +115,4 @@ public abstract class RowShifter extends BaseRowColShifter {
|
|||||||
// if the merged-region and the overwritten area intersect, we need to remove it
|
// if the merged-region and the overwritten area intersect, we need to remove it
|
||||||
return merged.intersects(overwrite);
|
return merged.intersects(overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for shifting columns up or down
|
* Helper for shifting columns up or down
|
||||||
|
*
|
||||||
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
// non-Javadoc: When possible, code should be implemented in the ColumnShifter abstract class to avoid duplication with
|
// 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}
|
// {@link org.apache.poi.hssf.usermodel.helpers.HSSFColumnShifter}
|
||||||
|
@ -37,9 +37,11 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for code common to {@link XSSFRowShifter} and {@link XSSFColumnShifter}
|
* Class for code common to {@link XSSFRowShifter} and {@link XSSFColumnShifter}
|
||||||
|
*
|
||||||
|
* @since POI 4.0.0
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
/*private*/ final class XSSFRowColShifter extends BaseRowColShifter {
|
/*private*/ final class XSSFRowColShifter {
|
||||||
private static final POILogger logger = POILogFactory.getLogger(XSSFRowColShifter.class);
|
private static final POILogger logger = POILogFactory.getLogger(XSSFRowColShifter.class);
|
||||||
|
|
||||||
private XSSFRowColShifter() { /*no instances for static classes*/}
|
private XSSFRowColShifter() { /*no instances for static classes*/}
|
||||||
@ -189,7 +191,7 @@ import java.util.List;
|
|||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
List<CellRangeAddress> temp = new ArrayList<>();
|
List<CellRangeAddress> temp = new ArrayList<>();
|
||||||
for (CellRangeAddress craOld : cellRanges) {
|
for (CellRangeAddress craOld : cellRanges) {
|
||||||
CellRangeAddress craNew = shiftRange(formulaShifter, craOld, sheetIndex);
|
CellRangeAddress craNew = BaseRowColShifter.shiftRange(formulaShifter, craOld, sheetIndex);
|
||||||
if (craNew == null) {
|
if (craNew == null) {
|
||||||
changed = true;
|
changed = true;
|
||||||
continue;
|
continue;
|
||||||
@ -234,7 +236,7 @@ import java.util.List;
|
|||||||
XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
|
XSSFHyperlink xhyperlink = (XSSFHyperlink) hyperlink;
|
||||||
String cellRef = xhyperlink.getCellRef();
|
String cellRef = xhyperlink.getCellRef();
|
||||||
CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
|
CellRangeAddress cra = CellRangeAddress.valueOf(cellRef);
|
||||||
CellRangeAddress shiftedRange = shiftRange(formulaShifter, cra, sheetIndex);
|
CellRangeAddress shiftedRange = BaseRowColShifter.shiftRange(formulaShifter, cra, sheetIndex);
|
||||||
if (shiftedRange != null && shiftedRange != cra) {
|
if (shiftedRange != null && shiftedRange != cra) {
|
||||||
// shiftedRange should not be null. If shiftedRange is null, that means
|
// shiftedRange should not be null. If shiftedRange is null, that means
|
||||||
// that a hyperlink wasn't deleted at the beginning of shiftRows when
|
// that a hyperlink wasn't deleted at the beginning of shiftRows when
|
||||||
|
@ -47,6 +47,12 @@ public final class XSSFRowShifter extends RowShifter {
|
|||||||
XSSFRowColShifter.updateFormulas(sheet, formulaShifter);
|
XSSFRowColShifter.updateFormulas(sheet, 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(since="3.15 beta 2")
|
@Internal(since="3.15 beta 2")
|
||||||
public void updateRowFormulas(XSSFRow row, FormulaShifter formulaShifter) {
|
public void updateRowFormulas(XSSFRow row, FormulaShifter formulaShifter) {
|
||||||
XSSFRowColShifter.updateRowFormulas(row, formulaShifter);
|
XSSFRowColShifter.updateRowFormulas(row, formulaShifter);
|
||||||
|
Loading…
Reference in New Issue
Block a user