Top Description Inners Fields Constructors Methods
org.apache.poi.ss.formula

public final Class FormulaShifter

extends Object
Class Inheritance
Imports
org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.ss.formula.ptg.Area2DPtgBase, .Area3DPtg, .Area3DPxg, .AreaErrPtg, .AreaPtg, .AreaPtgBase, .Deleted3DPxg, .DeletedArea3DPtg, .DeletedRef3DPtg, .Ptg, .Ref3DPtg, .Ref3DPxg, .RefErrorPtg, .RefPtg, .RefPtgBase

Updates Formulas as rows or sheets are shifted

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final int
private final int
private final int
_externSheetIndex

Extern sheet index of sheet where moving is occurring, used for updating HSSF style 3D references

private final int
private final int
private final FormulaShifter.ShiftMode
private final String
_sheetName

Sheet name of the sheet where moving is occurring, used for updating XSSF style 3D references on row shifts.

private final int
private final SpreadsheetVersion

Constructor Summary

AccessConstructor and Description
private
FormulaShifter(int externSheetIndex, String sheetName, int firstMovedIndex, int lastMovedIndex, int amountToMove, FormulaShifter.ShiftMode mode, SpreadsheetVersion version)

Create an instance for shifting row.

private
FormulaShifter(int srcSheetIndex, int dstSheetIndex)

Create an instance for shifting sheets.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if a change was made to the formula tokens
adjustFormula
(Ptg[]
- if necessary, will get modified by this method
ptgs
,
int
- the extern sheet index of the sheet that contains the formula being adjusted
currentExternSheetIx
)

private Ptg
adjustPtg(Ptg ptg, int currentExternSheetIx)

private Ptg

Returns:

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last column of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null
adjustPtgDueToColumnCopy
(Ptg
the ptg to shift
ptg
)

Call this on any ptg reference contained in a column of cells that was copied.

private Ptg

Returns:

in-place modified ptg (if column move would cause Ptg to change), deleted ref ptg (if column move causes an error), or null (if no Ptg change is needed)
adjustPtgDueToColumnMove
(Ptg ptg, int currentExternSheetIx)

private Ptg

Returns:

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last row or columns of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null
adjustPtgDueToCopy
(Ptg
the ptg to shift
ptg
,
boolean isRowCopy)

Call this on any ptg reference contained in a row or column of cells that was copied.

private Ptg

Returns:

in-place modified ptg (if column move would cause Ptg to change), deleted ref ptg (if column move causes an error), or null (if no Ptg change is needed)
adjustPtgDueToMove
(Ptg ptg, int currentExternSheetIx, boolean isRowMove)

private Ptg

Returns:

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last row of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null
adjustPtgDueToRowCopy
(Ptg
the ptg to shift
ptg
)

Call this on any ptg reference contained in a row of cells that was copied.

private Ptg

Returns:

in-place modified ptg (if row move would cause Ptg to change), deleted ref ptg (if row move causes an error), or null (if no Ptg change is needed)
adjustPtgDueToRowMove
(Ptg ptg, int currentExternSheetIx)

private Ptg
private Ptg

Returns:

null, AreaErrPtg, or modified aptg
columnCopyAreaPtg
(AreaPtgBase
The Area that is copied
aptg
)

Modifies aptg in-place and return a reference to aptg if the first or last column of of the Area reference would move due to a column copy operation Returns null or AreaErrPtg if no change was made

private Ptg

Returns:

The Ptg reference if the cell would move due to copy, otherwise null
columnCopyRefPtg
(RefPtgBase
The REF that is copied
rptg
)

Modifies rptg in-place and return a reference to rptg if the cell reference would move due to a column copy operation Returns null or RefErrorPtg if no change was made

private Ptg
private Ptg
private static Ptg
public static FormulaShifter
createForColumnCopy(int externSheetIndex, String sheetName, int firstMovedColumnIndex, int lastMovedColumnIndex, int numberOfColumnsToMove, SpreadsheetVersion version)

public static FormulaShifter
createForColumnShift(int externSheetIndex, String sheetName, int firstMovedColumnIndex, int lastMovedColumnIndex, int numberOfColumnsToMove, SpreadsheetVersion version)

public static FormulaShifter
createForRowCopy(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove, SpreadsheetVersion version)

public static FormulaShifter
createForRowShift(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove, SpreadsheetVersion version)

public static FormulaShifter
createForSheetShift(int srcSheetIndex, int dstSheetIndex)

private Ptg

Returns:

null, AreaErrPtg, or modified aptg
rowCopyAreaPtg
(AreaPtgBase
The Area that is copied
aptg
)

Modifies aptg in-place and return a reference to aptg if the first or last row of of the Area reference would move due to a row copy operation Returns null or AreaErrPtg if no change was made

private Ptg

Returns:

The Ptg reference if the cell would move due to copy, otherwise null
rowCopyRefPtg
(RefPtgBase
The REF that is copied
rptg
)

Modifies rptg in-place and return a reference to rptg if the cell reference would move due to a row copy operation Returns null or RefErrorPtg if no change was made

private Ptg
private Ptg
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_amountToMoveback to summary
private final int _amountToMove
_dstSheetIndexback to summary
private final int _dstSheetIndex
_externSheetIndexback to summary
private final int _externSheetIndex

Extern sheet index of sheet where moving is occurring, used for updating HSSF style 3D references

_firstMovedIndexback to summary
private final int _firstMovedIndex
_lastMovedIndexback to summary
private final int _lastMovedIndex
_modeback to summary
private final FormulaShifter.ShiftMode _mode
_sheetNameback to summary
private final String _sheetName

Sheet name of the sheet where moving is occurring, used for updating XSSF style 3D references on row shifts.

_srcSheetIndexback to summary
private final int _srcSheetIndex
_versionback to summary
private final SpreadsheetVersion _version

Constructor Detail

FormulaShifterback to summary
private FormulaShifter(int externSheetIndex, String sheetName, int firstMovedIndex, int lastMovedIndex, int amountToMove, FormulaShifter.ShiftMode mode, SpreadsheetVersion version)

Create an instance for shifting row. For example, this will be called on org.apache.poi.hssf.usermodel.HSSFSheet#shiftRows(int, int, int) }

FormulaShifterback to summary
private FormulaShifter(int srcSheetIndex, int dstSheetIndex)

Create an instance for shifting sheets. For example, this will be called on org.apache.poi.hssf.usermodel.HSSFWorkbook#setSheetOrder(String, int)

Method Detail

adjustFormulaback to summary
public boolean adjustFormula(Ptg[] ptgs, int currentExternSheetIx)
Parameters
ptgs:Ptg[]

- if necessary, will get modified by this method

currentExternSheetIx:int

- the extern sheet index of the sheet that contains the formula being adjusted

Returns:boolean

true if a change was made to the formula tokens

adjustPtgback to summary
private Ptg adjustPtg(Ptg ptg, int currentExternSheetIx)
adjustPtgDueToColumnCopyback to summary
private Ptg adjustPtgDueToColumnCopy(Ptg ptg)

Call this on any ptg reference contained in a column of cells that was copied. If the ptg reference is relative, the references will be shifted by the distance that the columns were copied.

Parameters
ptg:Ptg

the ptg to shift

Returns:Ptg

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last column of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null

adjustPtgDueToColumnMoveback to summary
private Ptg adjustPtgDueToColumnMove(Ptg ptg, int currentExternSheetIx)
Returns:Ptg

in-place modified ptg (if column move would cause Ptg to change), deleted ref ptg (if column move causes an error), or null (if no Ptg change is needed)

adjustPtgDueToCopyback to summary
private Ptg adjustPtgDueToCopy(Ptg ptg, boolean isRowCopy)

Call this on any ptg reference contained in a row or column of cells that was copied. If the ptg reference is relative, the references will be shifted by the distance that the rows or columns were copied.

Parameters
ptg:Ptg

the ptg to shift

Returns:Ptg

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last row or columns of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null

adjustPtgDueToMoveback to summary
private Ptg adjustPtgDueToMove(Ptg ptg, int currentExternSheetIx, boolean isRowMove)
Returns:Ptg

in-place modified ptg (if column move would cause Ptg to change), deleted ref ptg (if column move causes an error), or null (if no Ptg change is needed)

adjustPtgDueToRowCopyback to summary
private Ptg adjustPtgDueToRowCopy(Ptg ptg)

Call this on any ptg reference contained in a row of cells that was copied. If the ptg reference is relative, the references will be shifted by the distance that the rows were copied.

Parameters
ptg:Ptg

the ptg to shift

Returns:Ptg

deleted ref ptg, in-place modified ptg, or null If Ptg would be shifted off the first or last row of a sheet, return deleted ref If Ptg needs to be changed, modifies Ptg in-place If Ptg doesn't need to be changed, returns null

adjustPtgDueToRowMoveback to summary
private Ptg adjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx)
Returns:Ptg

in-place modified ptg (if row move would cause Ptg to change), deleted ref ptg (if row move causes an error), or null (if no Ptg change is needed)

adjustPtgDueToSheetMoveback to summary
private Ptg adjustPtgDueToSheetMove(Ptg ptg)
columnCopyAreaPtgback to summary
private Ptg columnCopyAreaPtg(AreaPtgBase aptg)

Modifies aptg in-place and return a reference to aptg if the first or last column of of the Area reference would move due to a column copy operation Returns null or AreaErrPtg if no change was made

Parameters
aptg:AreaPtgBase

The Area that is copied

Returns:Ptg

null, AreaErrPtg, or modified aptg

columnCopyRefPtgback to summary
private Ptg columnCopyRefPtg(RefPtgBase rptg)

Modifies rptg in-place and return a reference to rptg if the cell reference would move due to a column copy operation Returns null or RefErrorPtg if no change was made

Parameters
rptg:RefPtgBase

The REF that is copied

Returns:Ptg

The Ptg reference if the cell would move due to copy, otherwise null

columnMoveAreaPtgback to summary
private Ptg columnMoveAreaPtg(AreaPtgBase aptg)
columnMoveRefPtgback to summary
private Ptg columnMoveRefPtg(RefPtgBase rptg)
createDeletedRefback to summary
private static Ptg createDeletedRef(Ptg ptg)
createForColumnCopyback to summary
public static FormulaShifter createForColumnCopy(int externSheetIndex, String sheetName, int firstMovedColumnIndex, int lastMovedColumnIndex, int numberOfColumnsToMove, SpreadsheetVersion version)
Since
POI 4.0.0
createForColumnShiftback to summary
public static FormulaShifter createForColumnShift(int externSheetIndex, String sheetName, int firstMovedColumnIndex, int lastMovedColumnIndex, int numberOfColumnsToMove, SpreadsheetVersion version)
Since
POI 4.0.0
createForRowCopyback to summary
public static FormulaShifter createForRowCopy(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove, SpreadsheetVersion version)
createForRowShiftback to summary
public static FormulaShifter createForRowShift(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove, SpreadsheetVersion version)
createForSheetShiftback to summary
public static FormulaShifter createForSheetShift(int srcSheetIndex, int dstSheetIndex)
rowCopyAreaPtgback to summary
private Ptg rowCopyAreaPtg(AreaPtgBase aptg)

Modifies aptg in-place and return a reference to aptg if the first or last row of of the Area reference would move due to a row copy operation Returns null or AreaErrPtg if no change was made

Parameters
aptg:AreaPtgBase

The Area that is copied

Returns:Ptg

null, AreaErrPtg, or modified aptg

rowCopyRefPtgback to summary
private Ptg rowCopyRefPtg(RefPtgBase rptg)

Modifies rptg in-place and return a reference to rptg if the cell reference would move due to a row copy operation Returns null or RefErrorPtg if no change was made

Parameters
rptg:RefPtgBase

The REF that is copied

Returns:Ptg

The Ptg reference if the cell would move due to copy, otherwise null

rowMoveAreaPtgback to summary
private Ptg rowMoveAreaPtg(AreaPtgBase aptg)
rowMoveRefPtgback to summary
private Ptg rowMoveRefPtg(RefPtgBase rptg)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.apache.poi.ss.formula back to summary

private final Enum FormulaShifter.ShiftMode

extends Enum<FormulaShifter.ShiftMode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final FormulaShifter.ShiftMode
public static final FormulaShifter.ShiftMode
public static final FormulaShifter.ShiftMode
public static final FormulaShifter.ShiftMode
public static final FormulaShifter.ShiftMode

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static FormulaShifter.ShiftMode
public static FormulaShifter.ShiftMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ColumnCopyback to summary
public static final FormulaShifter.ShiftMode ColumnCopy
Since
POI 4.0.0
ColumnMoveback to summary
public static final FormulaShifter.ShiftMode ColumnMove
Since
POI 4.0.0
RowCopyback to summary
public static final FormulaShifter.ShiftMode RowCopy
RowMoveback to summary
public static final FormulaShifter.ShiftMode RowMove
SheetMoveback to summary
public static final FormulaShifter.ShiftMode SheetMove

Constructor Detail

ShiftModeback to summary
private ShiftMode()

Method Detail

valueOfback to summary
public static FormulaShifter.ShiftMode valueOf(String name)
valuesback to summary
public static FormulaShifter.ShiftMode[] values()