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