Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -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.
|
|
|
|
==================================================================== */
|
|
|
|
|
2010-11-21 06:41:38 -05:00
|
|
|
package org.apache.poi.ss.formula.functions;
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
|
2016-05-16 05:38:42 -04:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
2016-07-04 06:15:18 -04:00
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
import org.apache.poi.ss.usermodel.CellValue;
|
2016-05-16 05:38:42 -04:00
|
|
|
import org.apache.poi.ss.usermodel.FormulaError;
|
|
|
|
import org.junit.Test;
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
|
|
|
|
/**
|
2010-06-06 14:19:08 -04:00
|
|
|
* Tests for {@link Financed}
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
*/
|
2016-05-16 05:38:42 -04:00
|
|
|
public final class TestFind {
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
|
2016-05-16 05:38:42 -04:00
|
|
|
@Test
|
|
|
|
public void testFind() throws IOException {
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
|
|
|
|
|
|
|
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
|
|
|
|
|
|
|
|
confirmResult(fe, cell, "find(\"h\", \"haystack\")", 1);
|
|
|
|
confirmResult(fe, cell, "find(\"a\", \"haystack\",2)", 2);
|
|
|
|
confirmResult(fe, cell, "find(\"a\", \"haystack\",3)", 6);
|
|
|
|
|
|
|
|
// number args converted to text
|
|
|
|
confirmResult(fe, cell, "find(7, 32768)", 3);
|
|
|
|
confirmResult(fe, cell, "find(\"34\", 1341235233412, 3)", 10);
|
|
|
|
confirmResult(fe, cell, "find(5, 87654)", 4);
|
|
|
|
|
|
|
|
// Errors
|
2016-05-16 05:38:42 -04:00
|
|
|
confirmError(fe, cell, "find(\"n\", \"haystack\")", FormulaError.VALUE);
|
|
|
|
confirmError(fe, cell, "find(\"k\", \"haystack\",9)", FormulaError.VALUE);
|
|
|
|
confirmError(fe, cell, "find(\"k\", \"haystack\",#REF!)", FormulaError.REF);
|
|
|
|
confirmError(fe, cell, "find(\"k\", \"haystack\",0)", FormulaError.VALUE);
|
|
|
|
confirmError(fe, cell, "find(#DIV/0!, #N/A, #REF!)", FormulaError.DIV0);
|
|
|
|
confirmError(fe, cell, "find(2, #N/A, #REF!)", FormulaError.NA);
|
|
|
|
|
|
|
|
wb.close();
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void confirmResult(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText,
|
|
|
|
int expectedResult) {
|
|
|
|
cell.setCellFormula(formulaText);
|
|
|
|
fe.notifyUpdateCell(cell);
|
|
|
|
CellValue result = fe.evaluate(cell);
|
2016-09-13 19:24:56 -04:00
|
|
|
assertEquals(result.getCellTypeEnum(), CellType.NUMERIC);
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
assertEquals(expectedResult, result.getNumberValue(), 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void confirmError(HSSFFormulaEvaluator fe, HSSFCell cell, String formulaText,
|
2016-05-16 05:38:42 -04:00
|
|
|
FormulaError expectedErrorCode) {
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
cell.setCellFormula(formulaText);
|
|
|
|
fe.notifyUpdateCell(cell);
|
|
|
|
CellValue result = fe.evaluate(cell);
|
2016-09-13 19:24:56 -04:00
|
|
|
assertEquals(result.getCellTypeEnum(), CellType.ERROR);
|
2016-05-16 05:38:42 -04:00
|
|
|
assertEquals(expectedErrorCode.getCode(), result.getErrorValue());
|
Merged revisions 707953,708242,708252,708260,708262,708286 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r707953 | josh | 2008-10-26 01:17:06 -0700 (Sun, 26 Oct 2008) | 1 line
Bugzilla 45966 - added implementation for FIND function (patch from Torstein Tauno Svendsen).
........
r708242 | nick | 2008-10-27 10:26:52 -0700 (Mon, 27 Oct 2008) | 1 line
Link typo fix
........
r708252 | nick | 2008-10-27 10:59:39 -0700 (Mon, 27 Oct 2008) | 1 line
Patch from bug #46092 - fix hssf dev utility
........
r708260 | josh | 2008-10-27 11:12:09 -0700 (Mon, 27 Oct 2008) | 1 line
Removed obsolete class
........
r708262 | josh | 2008-10-27 11:16:44 -0700 (Mon, 27 Oct 2008) | 1 line
Bugzilla 46065 - added implementation for VALUE function
........
r708286 | josh | 2008-10-27 12:24:42 -0700 (Mon, 27 Oct 2008) | 1 line
Preparation for fix for bug 46009. (Bug visible on ooxml branch, but this change will expose the problem)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@708325 13f79535-47bb-0310-9956-ffa450edef68
2008-10-27 17:30:02 -04:00
|
|
|
}
|
|
|
|
}
|