You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2018/04/03 21:51:31 UTC
svn commit: r1828288 - in /poi/trunk/src:
java/org/apache/poi/ss/formula/functions/Offset.java
ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java
testcases/org/apache/poi/ss/formula/functions/TestOffset.java
Author: fanningpj
Date: Tue Apr 3 21:51:30 2018
New Revision: 1828288
URL: http://svn.apache.org/viewvc?rev=1828288&view=rev
Log:
[bug-62254] update offset function to support optional offset values
Added:
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java (with props)
Modified:
poi/trunk/src/java/org/apache/poi/ss/formula/functions/Offset.java
poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java
Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Offset.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Offset.java?rev=1828288&r1=1828287&r2=1828288&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Offset.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Offset.java Tue Apr 3 21:51:30 2018
@@ -163,18 +163,20 @@ public final class Offset implements Fun
@SuppressWarnings("fallthrough")
public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) {
- if(args.length < 3 || args.length > 5) {
+ if(args.length < 1 || args.length > 5) {
return ErrorEval.VALUE_INVALID;
}
try {
BaseRef baseRef = evaluateBaseRef(args[0]);
- int rowOffset = evaluateIntArg(args[1], srcCellRow, srcCellCol);
- int columnOffset = evaluateIntArg(args[2], srcCellRow, srcCellCol);
+ // optional arguments
+ // If offsets are omitted, it is assumed to be 0.
+ int rowOffset = (args[1] instanceof MissingArgEval) ? 0 : evaluateIntArg(args[1], srcCellRow, srcCellCol);
+ int columnOffset = (args[2] instanceof MissingArgEval) ? 0 : evaluateIntArg(args[2], srcCellRow, srcCellCol);
int height = baseRef.getHeight();
int width = baseRef.getWidth();
// optional arguments
- // If height or width is omitted, it is assumed to be the same height or width as reference.
+ // If height or width are omitted, it is assumed to be the same height or width as reference.
switch(args.length) {
case 5:
if(!(args[4] instanceof MissingArgEval)) {
Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java?rev=1828288&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java Tue Apr 3 21:51:30 2018
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.
+==================================================================== */
+
+package org.apache.poi.xssf;
+
+import java.io.IOException;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestXSSFOffset {
+
+ @Test
+ public void testOffsetWithEmpty23Arguments() throws IOException {
+ try (Workbook workbook = new XSSFWorkbook()) {
+ Cell cell = workbook.createSheet().createRow(0).createCell(0);
+ cell.setCellFormula("OFFSET(B1,,)");
+
+ String value = "EXPECTED_VALUE";
+ Cell valueCell = cell.getRow().createCell(1);
+ valueCell.setCellValue(value);
+
+ workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
+
+ assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
+ assertEquals(value, cell.getStringCellValue());
+ }
+ }
+}
Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/TestXSSFOffset.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java?rev=1828288&r1=1828287&r2=1828288&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestOffset.java Tue Apr 3 21:51:30 2018
@@ -17,12 +17,18 @@
package org.apache.poi.ss.formula.functions;
+import java.io.IOException;
+
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.functions.Offset.LinearOffsetRange;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Workbook;
/**
* Tests for OFFSET function implementation
@@ -96,4 +102,20 @@ public final class TestOffset extends Te
assertTrue(lor.isOutOfBounds(0, 16383));
assertFalse(lor.isOutOfBounds(0, 65535));
}
+
+ public void testOffsetWithEmpty23Arguments() throws IOException {
+ try (Workbook workbook = new HSSFWorkbook()) {
+ Cell cell = workbook.createSheet().createRow(0).createCell(0);
+ cell.setCellFormula("OFFSET(B1,,)");
+
+ String value = "EXPECTED_VALUE";
+ Cell valueCell = cell.getRow().createCell(1);
+ valueCell.setCellValue(value);
+
+ workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
+
+ assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
+ assertEquals(value, cell.getStringCellValue());
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org