From 8b82a8cb46d8262f4bfdd7a332682788bff2e4ca Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 7 Sep 2009 05:17:23 +0000 Subject: [PATCH] Added method setFunction(boolean) for defined names git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@811998 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/hssf/record/NameRecord.java | 16 ++++++++++++++++ .../org/apache/poi/hssf/usermodel/HSSFName.java | 11 +++++++++++ src/java/org/apache/poi/ss/usermodel/Name.java | 10 ++++++++++ .../poi/ss/usermodel/BaseTestNamedRange.java | 15 +++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 9d0d3a4a7f..21d2c70000 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 47771 - Added method setFunction(boolean) for defined names 47768 - Implementation of Excel "Days360" and "Npv" functions 47751 - Do not allow HSSF's cell text longer than 32,767 characters 47757 - Added an example demonstrating how to convert an XLSX workbook to CSV diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index c9b6f65708..6b38e36d4e 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -34,6 +34,8 @@ import org.apache.poi.util.StringUtil; * @author Sergei Kozello (sergeikozello at mail.ru) * @author Glen Stampoultzis (glens at apache.org) * @version 1.0-pre + * + * Modified 8/31/09 by Petr Udalau - added method setFunction(boolean) */ public final class NameRecord extends StandardRecord { public final static short sid = 0x0018; @@ -237,6 +239,20 @@ public final class NameRecord extends StandardRecord { public boolean isFunctionName() { return (field_1_option_flag & Option.OPT_FUNCTION_NAME) != 0; } + + /** + * Indicates that the defined name refers to a user-defined function. + * This attribute is used when there is an add-in or other code project associated with the file. + * + * @param value true indicates the name refers to a function. + */ + public void setFunction(boolean function){ + if (function) { + field_1_option_flag |= Option.OPT_FUNCTION_NAME; + } else { + field_1_option_flag &= (~Option.OPT_FUNCTION_NAME); + } + } /** * @return true if name has a formula (named range or defined value) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java index bceaf340ad..662ec2e1aa 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java @@ -243,4 +243,15 @@ public final class HSSFName implements Name { _definedNameRec.setDescriptionText(comment); } + /** + * Indicates that the defined name refers to a user-defined function. + * This attribute is used when there is an add-in or other code project associated with the file. + * + * @param value true indicates the name refers to a function. + */ + public void setFunction(boolean value) { + _definedNameRec.setFunction(value); + + } + } diff --git a/src/java/org/apache/poi/ss/usermodel/Name.java b/src/java/org/apache/poi/ss/usermodel/Name.java index 696eb3c1ac..0cc9d98e9e 100644 --- a/src/java/org/apache/poi/ss/usermodel/Name.java +++ b/src/java/org/apache/poi/ss/usermodel/Name.java @@ -49,6 +49,8 @@ package org.apache.poi.ss.usermodel; * name.setRefersToFormula("IF(Loan_Amount*Interest_Rate>0,1,0)"); * * + * + * Modified 8/31/09 by Petr Udalau - added method setFunction(boolean) */ public interface Name { @@ -181,4 +183,12 @@ public interface Name { * @param comment the user comment for this named range */ public void setComment(String comment); + + /** + * Indicates that the defined name refers to a user-defined function. + * This attribute is used when there is an add-in or other code project associated with the file. + * + * @param value true indicates the name refers to a function. + */ + void setFunction(boolean value); } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java index a645db57b3..08ce49b97d 100755 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java @@ -544,4 +544,19 @@ public abstract class BaseTestNamedRange extends TestCase { } } + + public void testFunctionNames() { + Workbook wb = getTestDataProvider().createWorkbook(); + Name n = wb.createName(); + assertFalse(n.isFunctionName()); + + n.setFunction(false); + assertFalse(n.isFunctionName()); + + n.setFunction(true); + assertTrue(n.isFunctionName()); + + n.setFunction(false); + assertFalse(n.isFunctionName()); + } } \ No newline at end of file -- 2.39.5