Follow-on from r713909 (bug 46174) - fixing Name to support general formulas

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@717882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-11-15 17:22:24 +00:00
parent 2e2062d99a
commit 647a9c8d73
2 changed files with 33 additions and 18 deletions

View File

@ -36,18 +36,25 @@ public interface Name {
*/
void setNameName(String nameName);
/**
* gets the reference of the named range
* @return reference of the named range
/**
* @deprecated (Nov 2008) Misleading name. Use {@link #getFormula()} instead.
*/
String getReference();
/**
* sets the reference of this named range
* @param ref the reference to set
/**
* @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead.
*/
void setReference(String ref);
/**
* @return the formula text defining this name
*/
String getFormula();
/**
* Sets the formula text defining this name
*/
void setFormula(String formulaText);
/**
* Checks if this name is a function name
*

View File

@ -18,8 +18,8 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
/**
@ -50,8 +50,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
* @author Nick Burch
* @author Yegor Kozlov
*/
public class XSSFName implements Name {
private static POILogger logger = POILogFactory.getLogger(XSSFWorkbook.class);
public final class XSSFName implements Name {
/**
* A built-in defined name that specifies the workbook's print area
@ -153,28 +152,37 @@ public class XSSFName implements Name {
ctName.setName(name);
}
/**
* @deprecated (Nov 2008) Misleading name. Use {@link #getFormula()} instead.
*/
public String getReference() {
return getFormula();
}
/**
* @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead.
*/
public void setReference(String ref){
setFormula(ref);
}
/**
* Returns the reference of this named range, such as Sales!C20:C30.
*
* @return the reference of this named range
*/
public String getReference() {
public String getFormula() {
return ctName.getStringValue();
}
/**
* Sets the reference of this named range, such as Sales!C20:C30.
*
* @param ref the reference to set
* @param formulaText the reference to set
* @throws IllegalArgumentException if the specified reference is unparsable
*/
public void setReference(String ref) {
try {
ref = AreaReference.isContiguous(ref) ? new AreaReference(ref).formatAsString() : ref;
} catch (IllegalArgumentException e){
logger.log(POILogger.WARN, "failed to parse cell reference. Setting raw value");
}
ctName.setStringValue(ref);
public void setFormula(String formulaText) {
// TODO parse formula and throw IllegalArgumentException if problem
ctName.setStringValue(formulaText);
}
/**