diff options
author | Josh Micich <josh@apache.org> | 2008-11-18 17:01:57 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2008-11-18 17:01:57 +0000 |
commit | 0e138a07a8d6908077ab1a6be2aba7bf3ad13ed4 (patch) | |
tree | 2a4ad9b0b7dc7c8909bb899ee4135e26d35e13f3 /src/ooxml/java/org/apache/poi/xssf | |
parent | 2a12f7566c812cd05291c31e1708178120f76a6e (diff) | |
download | poi-0e138a07a8d6908077ab1a6be2aba7bf3ad13ed4.tar.gz poi-0e138a07a8d6908077ab1a6be2aba7bf3ad13ed4.zip |
Fixed XSSFName and test cases
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@718651 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java index d4b87ab6d7..ebdfdd7238 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java @@ -16,10 +16,11 @@ ==================================================================== */ package org.apache.poi.xssf.usermodel; +import org.apache.poi.hssf.record.formula.Ptg; +import org.apache.poi.ss.formula.FormulaParser; +import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.util.AreaReference; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName; /** @@ -163,7 +164,7 @@ public final class XSSFName implements Name { * @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead. */ public void setReference(String ref){ - setFormula(ref); + setFormula(ref); } /** * Returns the reference of this named range, such as Sales!C20:C30. @@ -181,7 +182,16 @@ public final class XSSFName implements Name { * @throws IllegalArgumentException if the specified reference is unparsable */ public void setFormula(String formulaText) { - // TODO parse formula and throw IllegalArgumentException if problem + XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(workbook); + Ptg[] ptgs; + try { + ptgs = FormulaParser.parse(formulaText, fpb, FormulaType.CELL); // TODO - use type NAMEDRANGE + } catch (RuntimeException e) { + if (e.getClass().getName().startsWith(FormulaParser.class.getName())) { + throw new IllegalArgumentException("Unparsable formula '" + formulaText + "'"); + } + throw e; + } ctName.setStringValue(formulaText); } |