2008-09-04 16:58:37 -04:00
|
|
|
/* ====================================================================
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2008-08-31 21:48:45 -04:00
|
|
|
|
2008-09-18 22:19:58 -04:00
|
|
|
package org.apache.poi.ss.formula;
|
2008-08-31 21:48:45 -04:00
|
|
|
|
|
|
|
import org.apache.poi.hssf.record.formula.AreaI;
|
|
|
|
import org.apache.poi.hssf.record.formula.AreaI.OffsetArea;
|
2008-09-12 04:18:54 -04:00
|
|
|
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
|
|
|
import org.apache.poi.hssf.record.formula.eval.AreaEvalBase;
|
|
|
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
2008-09-04 16:58:37 -04:00
|
|
|
import org.apache.poi.hssf.util.CellReference;
|
2008-08-31 21:48:45 -04:00
|
|
|
|
|
|
|
/**
|
2008-09-04 16:58:37 -04:00
|
|
|
*
|
|
|
|
* @author Josh Micich
|
2008-08-31 21:48:45 -04:00
|
|
|
*/
|
2008-09-12 04:18:54 -04:00
|
|
|
final class LazyAreaEval extends AreaEvalBase {
|
2008-08-31 21:48:45 -04:00
|
|
|
|
2008-09-22 20:40:22 -04:00
|
|
|
private final SheetRefEvaluator _evaluator;
|
2008-08-31 21:48:45 -04:00
|
|
|
|
2008-09-22 20:40:22 -04:00
|
|
|
public LazyAreaEval(AreaI ptg, SheetRefEvaluator evaluator) {
|
2008-08-31 21:48:45 -04:00
|
|
|
super(ptg);
|
2008-09-04 19:16:15 -04:00
|
|
|
_evaluator = evaluator;
|
2008-08-31 21:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public ValueEval getRelativeValue(int relativeRowIndex, int relativeColumnIndex) {
|
|
|
|
|
|
|
|
int rowIx = (relativeRowIndex + getFirstRow() ) & 0xFFFF;
|
|
|
|
int colIx = (relativeColumnIndex + getFirstColumn() ) & 0x00FF;
|
|
|
|
|
2008-09-22 20:40:22 -04:00
|
|
|
return _evaluator.getEvalForCell(rowIx, colIx);
|
2008-08-31 21:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public AreaEval offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx) {
|
|
|
|
AreaI area = new OffsetArea(getFirstRow(), getFirstColumn(),
|
|
|
|
relFirstRowIx, relLastRowIx, relFirstColIx, relLastColIx);
|
|
|
|
|
2008-09-22 20:40:22 -04:00
|
|
|
return new LazyAreaEval(area, _evaluator);
|
2008-08-31 21:48:45 -04:00
|
|
|
}
|
2008-09-04 16:58:37 -04:00
|
|
|
public String toString() {
|
|
|
|
CellReference crA = new CellReference(getFirstRow(), getFirstColumn());
|
|
|
|
CellReference crB = new CellReference(getLastRow(), getLastColumn());
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
sb.append(getClass().getName()).append("[");
|
2008-09-22 20:40:22 -04:00
|
|
|
sb.append(_evaluator.getSheetName());
|
2008-09-04 16:58:37 -04:00
|
|
|
sb.append('!');
|
|
|
|
sb.append(crA.formatAsString());
|
|
|
|
sb.append(':');
|
|
|
|
sb.append(crB.formatAsString());
|
|
|
|
sb.append("]");
|
|
|
|
return sb.toString();
|
|
|
|
}
|
2008-08-31 21:48:45 -04:00
|
|
|
}
|