use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class FormulaRecordAggregate method getArrayFormulaRange.
public CellRangeAddress getArrayFormulaRange() {
if (_sharedFormulaRecord != null) {
throw new IllegalStateException("not an array formula cell.");
}
CellReference expRef = _formulaRecord.getFormula().getExpReference();
if (expRef == null) {
throw new IllegalStateException("not an array formula cell.");
}
ArrayRecord arec = _sharedValueManager.getArrayRecord(expRef.getRow(), expRef.getCol());
if (arec == null) {
throw new IllegalStateException("ArrayRecord was not found for the locator " + expRef.formatAsString());
}
CellRangeAddress8Bit a = arec.getRange();
return new CellRangeAddress(a.getFirstRow(), a.getLastRow(), a.getFirstColumn(), a.getLastColumn());
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class ConditionalFormattingEvaluator method getRules.
/**
* lazy load by sheet since reading can be expensive
*
* @param sheet
* @return unmodifiable list of rules
*/
protected List<EvaluationConditionalFormatRule> getRules(Sheet sheet) {
final String sheetName = sheet.getSheetName();
List<EvaluationConditionalFormatRule> rules = formats.get(sheetName);
if (rules == null) {
if (formats.containsKey(sheetName)) {
return Collections.emptyList();
}
final SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting();
final int count = scf.getNumConditionalFormattings();
rules = new ArrayList<EvaluationConditionalFormatRule>(count);
formats.put(sheetName, rules);
for (int i = 0; i < count; i++) {
ConditionalFormatting f = scf.getConditionalFormattingAt(i);
//optimization, as this may be expensive for lots of ranges
final CellRangeAddress[] regions = f.getFormattingRanges();
for (int r = 0; r < f.getNumberOfRules(); r++) {
ConditionalFormattingRule rule = f.getRule(r);
rules.add(new EvaluationConditionalFormatRule(workbookEvaluator, sheet, f, i, rule, r, regions));
}
}
// need them in formatting and priority order so logic works right
Collections.sort(rules);
}
return Collections.unmodifiableList(rules);
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class XSSFCell method convertSharedFormula.
/**
* Creates a non shared formula from the shared formula counterpart
*
* @param si Shared Group Index
* @return non shared formula created for the given shared formula and this cell
*/
private String convertSharedFormula(int si, XSSFEvaluationWorkbook fpb) {
XSSFSheet sheet = getSheet();
CTCellFormula f = sheet.getSharedFormula(si);
if (f == null) {
throw new IllegalStateException("Master cell of a shared formula with sid=" + si + " was not found");
}
String sharedFormula = f.getStringValue();
//Range of cells which the shared formula applies to
String sharedFormulaRange = f.getRef();
CellRangeAddress ref = CellRangeAddress.valueOf(sharedFormulaRange);
int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);
SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL2007);
Ptg[] ptgs = FormulaParser.parse(sharedFormula, fpb, FormulaType.CELL, sheetIndex, getRowIndex());
Ptg[] fmla = sf.convertSharedFormulas(ptgs, getRowIndex() - ref.getFirstRow(), getColumnIndex() - ref.getFirstColumn());
return FormulaRenderer.toFormulaString(fpb, fmla);
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class XSSFCell method notifyArrayFormulaChanging.
/**
* The purpose of this method is to validate the cell state prior to modification
*
* @see #notifyArrayFormulaChanging()
*/
void notifyArrayFormulaChanging(String msg) {
if (isPartOfArrayFormulaGroup()) {
CellRangeAddress cra = getArrayFormulaRange();
if (cra.getNumberOfCells() > 1) {
throw new IllegalStateException(msg);
}
//un-register the single-cell array formula from the parent XSSFSheet
getRow().getSheet().removeArrayFormula(this);
}
}
use of org.apache.poi.ss.util.CellRangeAddress in project poi by apache.
the class XSSFConditionalFormatting method setFormattingRanges.
@Override
public void setFormattingRanges(CellRangeAddress[] ranges) {
if (ranges == null) {
throw new IllegalArgumentException("cellRanges must not be null");
}
final StringBuilder sb = new StringBuilder();
boolean first = true;
for (CellRangeAddress range : ranges) {
if (!first) {
sb.append(" ");
} else {
first = false;
}
sb.append(range.formatAsString());
}
_cf.setSqref(Collections.singletonList(sb.toString()));
}
Aggregations