Added method setFunction(boolean) for defined names

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@811998 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-09-07 05:17:23 +00:00
parent 4f42192d39
commit dc05b63cb9
5 changed files with 53 additions and 0 deletions

View File

@ -33,6 +33,7 @@
<changes>
<release version="3.5-beta7" date="2009-??-??">
<action dev="POI-DEVELOPERS" type="add">47771 - Added method setFunction(boolean) for defined names</action>
<action dev="POI-DEVELOPERS" type="add">47768 - Implementation of Excel "Days360" and "Npv" functions</action>
<action dev="POI-DEVELOPERS" type="fix">47751 - Do not allow HSSF's cell text longer than 32,767 characters</action>
<action dev="POI-DEVELOPERS" type="add">47757 - Added an example demonstrating how to convert an XLSX workbook to CSV</action>

View File

@ -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 <code>true</code> 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 <code>true</code> if name has a formula (named range or defined value)

View File

@ -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 <code>true</code> indicates the name refers to a function.
*/
public void setFunction(boolean value) {
_definedNameRec.setFunction(value);
}
}

View File

@ -49,6 +49,8 @@ package org.apache.poi.ss.usermodel;
* name.setRefersToFormula("IF(Loan_Amount*Interest_Rate>0,1,0)");
*
* </blockquote></pre>
*
* 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 <code>true</code> indicates the name refers to a function.
*/
void setFunction(boolean value);
}

View File

@ -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());
}
}