net.sf.jett.util
Class FormulaUtil

java.lang.Object
  extended by net.sf.jett.util.FormulaUtil

public class FormulaUtil
extends java.lang.Object

The FormulaUtil utility class provides methods for Excel formula creation and manipulation.

Author:
Randy Gettman

Constructor Summary
FormulaUtil()
           
 
Method Summary
static void copyCellReferencesInRange(java.lang.String sheetName, java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap, int left, int right, int top, int bottom, int numCols, int numRows, java.lang.String currSuffix, java.lang.String newSuffix)
          Copies cell references that are on the same Sheet in the given cell reference map by the given number of rows and/or columns (usually one of those two will be zero).
static java.util.Map<java.lang.String,java.util.List<CellRef>> createCellRefMap(java.util.Map<java.lang.String,Formula> formulaMap)
          Finds unique cell references in all Formulas in the given formula map.
static java.lang.String createExcelFormulaString(java.lang.String formulaText, Formula formula, java.lang.String sheetName, WorkbookContext context)
          Replaces cell references in the given formula text with the translated cell references, and returns the formula string.
static void findAndReplaceCellRanges(java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap)
          Examines all CellRefs in each List.
static void shiftCellReferencesInRange(java.lang.String sheetName, java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap, int left, int right, int top, int bottom, int numCols, int numRows, boolean remove, boolean add)
          Shifts all CellRefs that are in range and on the same Sheet by the given number of rows and/or columns (usually one of those two will be zero).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormulaUtil

public FormulaUtil()
Method Detail

createCellRefMap

public static java.util.Map<java.lang.String,java.util.List<CellRef>> createCellRefMap(java.util.Map<java.lang.String,Formula> formulaMap)
Finds unique cell references in all Formulas in the given formula map.

Parameters:
formulaMap - A formula map.
Returns:
A cell reference map, a Map of cell key strings to Lists of CellRefs. Each List is initialized to contain only one CellRef, the original from the cell key string, e.g. "Sheet1!C2" => [Sheet1!C2]

createExcelFormulaString

public static java.lang.String createExcelFormulaString(java.lang.String formulaText,
                                                        Formula formula,
                                                        java.lang.String sheetName,
                                                        WorkbookContext context)
Replaces cell references in the given formula text with the translated cell references, and returns the formula string.

Parameters:
formulaText - The Formula text, e.g. "SUM(C2)".
formula - The FormulaCellRefs.
sheetName - The name of the Sheet on which the formula exists.
context - The WorkbookContext, for its access to the cell reference map.
Returns:
A string suitable for an Excel formula, for use in the method Cell.setCellFormula().

findAndReplaceCellRanges

public static void findAndReplaceCellRanges(java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap)
Examines all CellRefs in each List. If a group of CellRefs represent a linear range, horizontally or vertically, then they are replaced with a CellRefRange.

Parameters:
cellRefMap - The cell reference map.

shiftCellReferencesInRange

public static void shiftCellReferencesInRange(java.lang.String sheetName,
                                              java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap,
                                              int left,
                                              int right,
                                              int top,
                                              int bottom,
                                              int numCols,
                                              int numRows,
                                              boolean remove,
                                              boolean add)
Shifts all CellRefs that are in range and on the same Sheet by the given number of rows and/or columns (usually one of those two will be zero). Modifies the Lists that are the values of cellRefMap.

Parameters:
sheetName - The name of the Sheet on which to shift cell references.
cellRefMap - The Map of cell key strings, representing original cell locations, to Lists of current CellRefs.
left - The 0-based index of the column on which to start shifting cell references.
right - The 0-based index of the column on which to end shifting cell references.
top - The 0-based index of the row on which to start shifting cell references.
bottom - The 0-based index of the row on which to end shifting cell references.
numCols - The number of columns to shift the cell reference (can be negative).
numRows - The number of rows to shift the cell reference (can be negative).
remove - Determines whether to remove the old cell reference, resulting in a shift, or not to remove the old cell reference, resulting in a copy.
add - Determines whether to add the new cell reference, resulting in a copy, or not to add the new cell reference, resulting in a shift.

copyCellReferencesInRange

public static void copyCellReferencesInRange(java.lang.String sheetName,
                                             java.util.Map<java.lang.String,java.util.List<CellRef>> cellRefMap,
                                             int left,
                                             int right,
                                             int top,
                                             int bottom,
                                             int numCols,
                                             int numRows,
                                             java.lang.String currSuffix,
                                             java.lang.String newSuffix)
Copies cell references that are on the same Sheet in the given cell reference map by the given number of rows and/or columns (usually one of those two will be zero). Modifies the Lists that are the values of cellRefMap.

Parameters:
sheetName - The name of the Sheet on which to copy references.
cellRefMap - The Map of cell key strings, representing original cell locations, to Lists of current CellRefs.
left - The 0-based index of the column on which to start shifting cell references.
right - The 0-based index of the column on which to end shifting cell references.
top - The 0-based index of the row on which to start shifting cell references.
bottom - The 0-based index of the row on which to end shifting cell references.
numCols - The number of columns to shift the cell reference (can be negative).
numRows - The number of rows to shift the cell reference (can be negative).
currSuffix - The current "[loop,iter]*" suffix we're already in.
newSuffix - The new "[loop,iter]" suffix to add for new entries.


Copyright © 2012-2013 Jett Team. All Rights Reserved.