From: Josh Micich Date: Tue, 31 Mar 2009 06:09:06 +0000 (+0000) Subject: Bugzilla 46818 (patch from Wayne Clingingsmith) - added implementation for HYPERLINK... X-Git-Tag: REL_3_5_BETA6~80 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d91c7b31fe70b5857abd2ce19a10974028f23a5;p=poi.git Bugzilla 46818 (patch from Wayne Clingingsmith) - added implementation for HYPERLINK function git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@760343 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java b/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java index 020d40d87f..d729762a50 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/Hyperlink.java @@ -1,25 +1,56 @@ -/* -* 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. -*/ -/* - * Created on May 15, 2005 - * - */ +/* ==================================================================== + 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.hssf.record.formula.functions; -public class Hyperlink extends NotImplementedFunction { +import org.apache.poi.hssf.record.formula.eval.ErrorEval; +import org.apache.poi.hssf.record.formula.eval.Eval; +import org.apache.poi.hssf.record.formula.eval.EvaluationException; +import org.apache.poi.hssf.record.formula.eval.OperandResolver; +import org.apache.poi.hssf.record.formula.eval.StringEval; + +/** + * Implementation of Excel HYPERLINK function.

+ * + * In Excel this function has special behaviour - it causes the displayed cell value to behave like + * a hyperlink in the GUI. From an evaluation perspective however, it is very simple.

+ * + * Syntax:
+ * HYPERLINK(link_location, friendly_name)

+ * + * link_location The URL of the hyperlink
+ * friendly_name (optional) the value to display

+ * + * Returns last argument. Leaves type unchanged (does not convert to {@link StringEval}). + + * @author Wayne Clingingsmith + */ +public class Hyperlink implements Function { + + public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { + int lastArgIx = operands.length - 1; + if (lastArgIx < 0 || lastArgIx > 1) { + return ErrorEval.VALUE_INVALID; + } + try { + return OperandResolver.getSingleValue(operands[lastArgIx], srcRow, srcCol); + } catch (EvaluationException e) { + return e.getErrorEval(); + } + } }