]> source.dussan.org Git - poi.git/commitdiff
renamed Name.setFormula to more descriptive setRefersToFormula, also misc improvement...
authorYegor Kozlov <yegor@apache.org>
Fri, 21 Nov 2008 09:22:07 +0000 (09:22 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 21 Nov 2008 09:22:07 +0000 (09:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@719547 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
src/documentation/content/xdocs/spreadsheet/how-to.xml
src/documentation/content/xdocs/spreadsheet/quick-guide.xml
src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java
src/java/org/apache/poi/hssf/usermodel/HSSFName.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Name.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
src/testcases/org/apache/poi/hssf/record/TestNameRecord.java

index 8451813f0fc1854015732114502e8d2dc4af94f2..d21be707e215ee4d5e731be0ed33a76c76451a2d 100644 (file)
@@ -182,6 +182,7 @@ wb.setSheetName(0, "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F " +
 // in case of plain ascii
 // wb.setSheetName(0, "HSSF Test");
 // create a sheet with 30 rows (0-29)
+int rownum;
 for (rownum = (short) 0; rownum < 30; rownum++)
 {
     // create a row
index 2688bc9f234d6fe278b4aebb2de97e51b5a40454..e7d2ae798bc18bd9077c97994d84a04b0afa1f0a 100644 (file)
@@ -1243,19 +1243,24 @@ Examples:
     Name namedCell = wb.createName();
     namedCell.setNameName(cname);
     String reference = sname+"!A1:A1"; // area reference
-    namedCell.setReference(reference);
+    namedCell.setRefersToFormula(reference);
 
     // 2. create named range for a single cell using cellreference
-    Name namedCell = wb.createName();
-    namedCell.setNameName(cname);
+    Name namedCel2 = wb.createName();
+    namedCel2.setNameName(cname);
     String reference = sname+"!A1"; // cell reference
-    namedCell.setReference(reference);
+    namedCel2.setRefersToFormula(reference);
 
     // 3. create named range for an area using AreaReference
-    Name namedCell = wb.createName();
-    namedCell.setNameName(cname);
+    Name namedCel3 = wb.createName();
+    namedCel3.setNameName(cname);
     String reference = sname+"!A1:C5"; // area reference
-    namedCell.setReference(reference);
+    namedCel3.setRefersToFormula(reference);
+
+    // 4. create named formula
+    Name namedCel4 = wb.createName();
+    namedCel4.setNameName("my_sum");
+    namedCel4.setRefersToFormula("SUM(sname+!$I$2:$I$6)");
             </source>
             <p>
             Reading from Named Range / Named Cell
@@ -1270,7 +1275,7 @@ Examples:
     Name aNamedCell = wb.getNameAt(namedCellIdx);
 
     // retrieve the cell at the named range and test its contents
-    AreaReference aref = new AreaReference(aNamedCell.getReference());
+    AreaReference aref = new AreaReference(aNamedCell.getRefersToFormula());
     CellReference[] crefs = aref.getAllReferencedCells();
     for (int i=0; i&lt;crefs.length; i++) {
         Sheet s = wb.getSheet(crefs[i].getSheetName());
@@ -1295,7 +1300,7 @@ Examples:
     // Retrieve the cell at the named range and test its contents
     // Will get back one AreaReference for C10, and
     //  another for D12 to D14
-    AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getReference());
+    AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getRefersToFormula());
     for (int i=0; i&lt;arefs.length; i++) {
         // Only get the corners of the Area
         // (use arefs[i].getAllReferencedCells() to get all cells)
@@ -1320,7 +1325,7 @@ Examples:
     if(name.isDeleted()){
       //named range points to a deleted cell. 
     } else {
-      AreaReference ref = new AreaReference(name.getReference());
+      AreaReference ref = new AreaReference(name.getRefersToFormula());
     }
             </source>
         </section>
index 96bb5f1652ea72d3b6545b466ab1147ff3b6cb7a..3323c9e2d63797c34a93b62e1d127b42bed9f8f2 100755 (executable)
@@ -267,38 +267,38 @@ public class LoanCalculator {
 \r
         name = wb.createName();\r
         name.setNameName("Interest_Rate");\r
-        name.setReference("'Loan Calculator'!$E$5");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$5");\r
 \r
         name = wb.createName();\r
         name.setNameName("Loan_Amount");\r
-        name.setReference("'Loan Calculator'!$E$4");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$4");\r
 \r
         name = wb.createName();\r
         name.setNameName("Loan_Start");\r
-        name.setReference("'Loan Calculator'!$E$7");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$7");\r
 \r
         name = wb.createName();\r
         name.setNameName("Loan_Years");\r
-        name.setReference("'Loan Calculator'!$E$6");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$6");\r
 \r
         name = wb.createName();\r
         name.setNameName("Number_of_Payments");\r
-        name.setReference("'Loan Calculator'!$E$10");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$10");\r
 \r
         name = wb.createName();\r
         name.setNameName("Monthly_Payment");\r
-        name.setReference("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");\r
+        name.setRefersToFormula("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");\r
 \r
         name = wb.createName();\r
         name.setNameName("Total_Cost");\r
-        name.setReference("'Loan Calculator'!$E$12");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$12");\r
 \r
         name = wb.createName();\r
         name.setNameName("Total_Interest");\r
-        name.setReference("'Loan Calculator'!$E$11");\r
+        name.setRefersToFormula("'Loan Calculator'!$E$11");\r
 \r
         name = wb.createName();\r
         name.setNameName("Values_Entered");\r
-        name.setReference("IF(Loan_Amount*Interest_Rate*Loan_Years*Loan_Start>0,1,0)");\r
+        name.setRefersToFormula("IF(Loan_Amount*Interest_Rate*Loan_Years*Loan_Start>0,1,0)");\r
     }\r
 }\r
index bcd1977200ae177ae006ba504f3ad4431eae3dcb..cc2f4447171c3409abfe00518ada271e10ce2ba6 100644 (file)
@@ -62,8 +62,28 @@ public final class HSSFName implements Name {
     }
 
     /**
-     * sets the name of the named range
+     * Sets the name of the named range
+     *
+     * <p>The following is a list of syntax rules that you need to be aware of when you create and edit names.</p>
+     * <ul>
+     *   <li><strong>Valid characters</strong>
+     *   The first character of a name must be a letter, an underscore character (_), or a backslash (\).
+     *   Remaining characters in the name can be letters, numbers, periods, and underscore characters.
+     *   </li>
+     *   <li><strong>Cell references disallowed</strong>
+     *   Names cannot be the same as a cell reference, such as Z$100 or R1C1.</li>
+     *   <li><strong>Spaces are not valid</strong>
+     *   Spaces are not allowed as part of a name. Use the underscore character (_) and period (.) as word separators, such as, Sales_Tax or First.Quarter.
+     *   </li>
+     *   <li><strong>Name length</strong>
+     *    A name can contain up to 255 characters.
+     *   </li>
+     *   <li><strong>Case sensitivity</strong>
+     *   Names can contain uppercase and lowercase letters.
+     *   </li>
+     * </ul>
      * @param nameName named range name to set
+     * @throws IllegalArgumentException if the name is invalid or the workbook already contains this name (case-insensitive)
      */
     public void setNameName(String nameName){
         _definedNameRec.setNameText(nameName);
@@ -81,29 +101,49 @@ public final class HSSFName implements Name {
     }
 
     /**
-     * @deprecated (Nov 2008) Misleading name. Use {@link #getFormula()} instead.
+     * Returns the formula that the name is defined to refer to.
+     *
+     * @deprecated (Nov 2008) Misleading name. Use {@link #getRefersToFormula()} instead.
      */
     public String getReference() {
-        return getFormula();
+        return getRefersToFormula();
     }
 
     /**
-     * @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead.
+     * Sets the formula that the name is defined to refer to.
+     *
+     * @deprecated (Nov 2008) Misleading name. Use {@link #setRefersToFormula(String)} instead.
      */
     public void setReference(String ref){
-       setFormula(ref);
+       setRefersToFormula(ref);
     }
 
-    public void setFormula(String formulaText) {
+    /**
+     * Sets the formula that the name is defined to refer to. The following are representative examples:
+     *
+     * <ul>
+     *  <li><code>'My Sheet'!$A$3</code></li>
+     *  <li><code>8.3</code></li>
+     *  <li><code>HR!$A$1:$Z$345</code></li>
+     *  <li><code>SUM(Sheet1!A1,Sheet2!B2)</li>
+     *  <li><code>-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)</li>
+     * </ul>
+     *
+     * @param formulaText the reference for this name
+     * @throws IllegalArgumentException if the specified reference is unparsable
+    */
+    public void setRefersToFormula(String formulaText) {
                Ptg[] ptgs = HSSFFormulaParser.parse(formulaText, _book);
        _definedNameRec.setNameDefinition(ptgs);
        }
 
     /**
-     * Note - this method only applies to named ranges
-     * @return the formula text defining this name
+     * Returns the formula that the name is defined to refer to. The following are representative examples:
+     *
+     * @return the reference for this name
+     * @see #setRefersToFormula(String)
      */
-    public String getFormula() {
+    public String getRefersToFormula() {
         if (_definedNameRec.isFunctionName()) {
             throw new IllegalStateException("Only applicable to named ranges");
         }
@@ -116,20 +156,19 @@ public final class HSSFName implements Name {
      * @return true if the name refers to a deleted cell, false otherwise
      */
     public boolean isDeleted(){
-        String formulaText = getReference();
-        if (formulaText.startsWith("#REF!")) {
-               // sheet deleted
-               return true;
-        }
-        if (formulaText.endsWith("#REF!")) {
-               // cell range deleted
-               return true;
-        }
-        return false;
+        String formulaText = getRefersToFormula();
+        return formulaText.indexOf("#REF!") != -1;
     }
+
+    /**
+     * Checks if this name is a function name
+     *
+     * @return true if this name is a function name
+     */
     public boolean isFunctionName() {
         return _definedNameRec.isFunctionName();
     }
+
     public String toString() {
         StringBuffer sb = new StringBuffer(64);
         sb.append(getClass().getName()).append(" [");
index 6ca59a651f3815599b2d4ca344dc0d175b677460..b896b30ee76ffc9ec1241bfdc19a23c74016f205 100644 (file)
 
 package org.apache.poi.ss.usermodel;
 
+/**
+ * Represents a defined name for a range of cells.
+ * <p>
+ * A name is a meaningful shorthand that makes it easier to understand the purpose of a
+ * cell reference, constant or a formula.
+ * </p>
+ * Examples:
+ * <pre><blockquote>
+ *  Sheet sheet = workbook.createSheet("Loan Calculator");
+ *  Name name;
+ *
+ *  name = workbook.createName();
+ *  name.setNameName("Interest_Rate");
+ *  name.setRefersToFormula("'Loan Calculator'!$E$5");
+ *
+ *  name = wb.createName();
+ *  name.setNameName("Loan_Amount");
+ *  name.setRefersToFormula("'Loan Calculator'!$E$4");
+ *
+ *  name = wb.createName();
+ *  name.setNameName("Number_of_Payments");
+ *  name.setRefersToFormula("'Loan Calculator'!$E$10");
+ *
+ *  name = wb.createName();
+ *  name.setNameName("Monthly_Payment");
+ *  name.setRefersToFormula("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");
+ *
+ *  name = wb.createName();
+ *  name.setNameName("Values_Entered");
+ *  name.setRefersToFormula("IF(Loan_Amount*Interest_Rate>0,1,0)");
+ *
+ * </blockquote></pre>
+ */
 public interface Name {
 
-    /** Get the sheets name which this named range is referenced to
+    /**
+     * Get the sheets name which this named range is referenced to
+     *
      * @return sheet name, which this named range refered to
      */
     String getSheetName();
 
     /** 
-     * gets the name of the named range
+     * Gets the name of the named range
+     *
      * @return named range name
      */
     String getNameName();
 
     /** 
-     * sets the name of the named range
-     * @param nameName named range name to set
+     * Sets the name of the named range
+     *
+     * <p>The following is a list of syntax rules that you need to be aware of when you create and edit names.</p>
+     * <ul>
+     *   <li><strong>Valid characters</strong>
+     *   The first character of a name must be a letter, an underscore character (_), or a backslash (\).
+     *   Remaining characters in the name can be letters, numbers, periods, and underscore characters.
+     *   </li>
+     *   <li><strong>Cell references disallowed</strong>
+     *   Names cannot be the same as a cell reference, such as Z$100 or R1C1.</li>
+     *   <li><strong>Spaces are not valid</strong>
+     *   Spaces are not allowed as part of a name. Use the underscore character (_) and period (.) as word separators, such as, Sales_Tax or First.Quarter.
+     *   </li>
+     *   <li><strong>Name length</strong>
+     *    A name can contain up to 255 characters.
+     *   </li>
+     *   <li><strong>Case sensitivity</strong>
+     *   Names can contain uppercase and lowercase letters.
+     *   </li>
+     * </ul>
+     * @param name named range name to set
+     * @throws IllegalArgumentException if the name is invalid or the workbook already contains this name (case-insensitive)
      */
-    void setNameName(String nameName);
+    void setNameName(String name);
 
     /**
-     * @deprecated (Nov 2008) Misleading name. Use {@link #getFormula()} instead.
+     * Returns the formula that the name is defined to refer to. The following are representative examples:
+     *
+     * @return the reference for this name
+     * @see #setRefersToFormula(String)
      */
-    String getReference();
+    String getRefersToFormula();
 
     /**
-     * @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead.
-     */
-   void setReference(String ref);
-
-   /**
-     * @return the formula text defining this name
+     * Sets the formula that the name is defined to refer to. The following are representative examples:
+     *
+     * <ul>
+     *  <li><code>'My Sheet'!$A$3</code></li>
+     *  <li><code>8.3</code></li>
+     *  <li><code>HR!$A$1:$Z$345</code></li>
+     *  <li><code>SUM(Sheet1!A1,Sheet2!B2)</li>
+     *  <li><code>-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)</li>
+     * </ul>
+     *
+     * @param ref the reference for this name
+     * @throws IllegalArgumentException if the specified reference is unparsable
     */
-   String getFormula();
-   
-   /**
-    * Sets the formula text defining this name
-   */
-   void setFormula(String formulaText);
+   void setRefersToFormula(String ref);
+
     /**
      * Checks if this name is a function name
      *
index e280a350289eb41fea0d74aea13bf12057e8b30b..7e7645995b8fb6175418d16b92e2fcce9571bac1 100644 (file)
@@ -233,7 +233,7 @@ public interface Sheet extends Iterable<Row> {
      *
      * @param value <code>true</code> if the sheet displays Automatic Page Breaks.
      */
-    void setAutobreaks(boolean b);
+    void setAutobreaks(boolean value);
 
     /**
      * Set whether to display the guts or not
index 35b947ae443199ca37d9b3abf8e36752d7afb63a..fdcebbcc9966f955b6990777ffee7d46870a8f08 100644 (file)
@@ -152,7 +152,7 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E
 \r
                public Ptg[] getNameDefinition() {\r
                        \r
-                       return FormulaParser.parse(_nameRecord.getReference(), _fpBook);\r
+                       return FormulaParser.parse(_nameRecord.getRefersToFormula(), _fpBook);\r
                }\r
 \r
                public String getNameText() {\r
index 2be7cffa590a99667401398fa514c4976c133f83..1813892ba9f68a6e28d4e94a9b4d6aa45b38b2b9 100644 (file)
@@ -37,14 +37,14 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
  *   //applies to the entire workbook
  *   XSSFName name1 = wb.createName();
  *   name1.setNameName("FMLA");
- *   name1.setReference("Sheet1!$B$3");
+ *   name1.setRefersToFormula("Sheet1!$B$3");
  *
  *   //applies to Sheet1
  *   XSSFName name2 = wb.createName();
  *   name2.setNameName("SheetLevelName");
  *   name2.setComment("This name is scoped to Sheet1");
  *   name2.setLocalSheetId(0);
- *   name2.setReference("Sheet1!$B$3");
+ *   name2.setRefersToFormula("Sheet1!$B$3");
  *
  * </blockquote></pre>
  *
@@ -153,25 +153,12 @@ public final 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 getFormula() {
+    public String getRefersToFormula() {
         return ctName.getStringValue();
     }
 
@@ -181,7 +168,7 @@ public final class XSSFName implements Name {
      * @param formulaText the reference to set
      * @throws IllegalArgumentException if the specified reference is unparsable
      */
-    public void setFormula(String formulaText) {
+    public void setRefersToFormula(String formulaText) {
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(workbook);
         Ptg[] ptgs;
         try {
@@ -201,7 +188,7 @@ public final class XSSFName implements Name {
      * @return true if the name refers to a deleted cell, false otherwise
      */
     public boolean isDeleted(){
-        String ref = getReference();
+        String ref = getRefersToFormula();
         return ref != null && ref.indexOf("#REF!") != -1;
     }
 
@@ -278,7 +265,7 @@ public final class XSSFName implements Name {
             int sheetId = (int)ctName.getLocalSheetId();
             return workbook.getSheetName(sheetId);
         } else {
-            String ref = getReference();
+            String ref = getRefersToFormula();
             AreaReference areaRef = new AreaReference(ref);
             return areaRef.getFirstCell().getSheetName();
         }
index 63f9152b89c7da67c1aeebcdba145aeea742dd0c..0597f677b08f0f67e0adde1786523194ede3a886 100644 (file)
@@ -617,7 +617,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_AREA, sheetIndex);
         if (name == null) return null;
         //adding one here because 0 indicates a global named region; doesnt make sense for print areas
-        return name.getReference();
+        return name.getRefersToFormula();
 
     }
 
@@ -871,7 +871,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
             sb.append("!");
             sb.append(parts[i]);
         }
-        name.setFormula(sb.toString());
+        name.setRefersToFormula(sb.toString());
     }
 
     /**
@@ -931,7 +931,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         if (name == null) {
             name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
             String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
-            name.setReference(reference);
+            name.setRefersToFormula(reference);
             namedRanges.add(name);
         }
 
index e5e7fd4f58682ad6c52f57c63dbc00540ad427ea..450686b8350bbe1739300dd701d1aa7817645570 100644 (file)
@@ -657,7 +657,7 @@ public class XWPFParagraph {
      * Specifies the spacing that should be added above the first line in this
      * paragraph in the document in absolute units.
      *
-     * @return
+     * @return the spacing that should be added above the first line
      * @see #setSpacingBefore(BigInteger)
      */
     public BigInteger getSpacingBefore() {
@@ -687,7 +687,7 @@ public class XWPFParagraph {
      * document in line units.
      * The value of this attribute is specified in one hundredths of a line.
      *
-     * @return
+     * @return the spacing that should be added before the first line in this paragraph
      * @see #setSpacingBeforeLines(BigInteger)
      */
     public BigInteger getSpacingBeforeLines() {
index b3f3e533dd79360f15c151c4c458446b9fef087f..bf5f330cf98675b340dbe06e6140087078caf090 100644 (file)
@@ -48,23 +48,23 @@ public class TestXSSFBugs extends TestCase {
 
         assertEquals(0, wb.getNameAt(0).getCTName().getLocalSheetId());
         assertFalse(wb.getNameAt(0).getCTName().isSetLocalSheetId());
-        assertEquals("SheetA!$A$1", wb.getNameAt(0).getReference());
+        assertEquals("SheetA!$A$1", wb.getNameAt(0).getRefersToFormula());
         assertEquals("SheetA", wb.getNameAt(0).getSheetName());
 
         assertEquals(0, wb.getNameAt(1).getCTName().getLocalSheetId());
         assertFalse(wb.getNameAt(1).getCTName().isSetLocalSheetId());
-        assertEquals("SheetB!$A$1", wb.getNameAt(1).getReference());
+        assertEquals("SheetB!$A$1", wb.getNameAt(1).getRefersToFormula());
         assertEquals("SheetB", wb.getNameAt(1).getSheetName());
 
         assertEquals(0, wb.getNameAt(2).getCTName().getLocalSheetId());
         assertFalse(wb.getNameAt(2).getCTName().isSetLocalSheetId());
-        assertEquals("SheetC!$A$1", wb.getNameAt(2).getReference());
+        assertEquals("SheetC!$A$1", wb.getNameAt(2).getRefersToFormula());
         assertEquals("SheetC", wb.getNameAt(2).getSheetName());
 
         // Save and re-load, still there
         XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
         assertEquals(3, nwb.getNumberOfNames());
-        assertEquals("SheetA!$A$1", nwb.getNameAt(0).getReference());
+        assertEquals("SheetA!$A$1", nwb.getNameAt(0).getRefersToFormula());
     }
 
     /**
index 3273bc03a2e3d3c6cf89662d9a47ae3d6f831c81..af1a48eccef2700b4bed6b8f9896b31c3fd7ca91 100755 (executable)
@@ -43,14 +43,13 @@ public class TestXSSFName extends TestCase {
         name2.setNameName("testTwo");\r
 \r
         String ref1 = "Test1!$A$1:$B$1";\r
-        name1.setReference(ref1);\r
-        assertEquals(ref1, name1.getReference());\r
+        name1.setRefersToFormula(ref1);\r
+        assertEquals(ref1, name1.getRefersToFormula());\r
         assertEquals("Test1", name1.getSheetName());\r
 \r
         String ref2 = "'Testing Named Ranges'!$A$1:$B$1";\r
-        name1.setReference(ref2);\r
-        //XSSFName#setReference stores the reference in canonical form and puts the sheet name in single quotes\r
-        assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getReference());\r
+        name1.setRefersToFormula(ref2);\r
+        assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getRefersToFormula());\r
         assertEquals("Testing Named Ranges", name1.getSheetName());\r
 \r
         assertEquals(-1, name1.getLocalSheetId());\r
@@ -63,14 +62,14 @@ public class TestXSSFName extends TestCase {
         workBook.createSheet("Test");\r
         XSSFName name = workBook.createName();\r
         name.setNameName("\u03B1");\r
-        name.setReference("Test!$D$3:$E$8");\r
+        name.setRefersToFormula("Test!$D$3:$E$8");\r
 \r
 \r
         XSSFWorkbook workBook2 = XSSFTestDataSamples.writeOutAndReadBack(workBook);\r
         XSSFName name2 = workBook2.getNameAt(0);\r
 \r
         assertEquals("\u03B1", name2.getNameName());\r
-        assertEquals("Test!$D$3:$E$8", name2.getReference());\r
+        assertEquals("Test!$D$3:$E$8", name2.getRefersToFormula());\r
     }\r
 \r
     public void testAddRemove() {\r
index b5694adf715c3a253a9b16722b2d85a7e8c68e20..4b8ebaca7b02fc09e195a27f1cd69e71135e6ef0 100644 (file)
@@ -183,7 +183,7 @@ public final class TestXSSFWorkbook extends TestCase {
                XSSFName nr1 = wb.getNameAt(0);
                
                assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-               assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getReference());
+               assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
                
                // Save and re-open
                XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -192,7 +192,7 @@ public final class TestXSSFWorkbook extends TestCase {
                nr1 = nwb.getNameAt(0);
                
                assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-               assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getReference());
+               assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
                
                // check that setting RR&C on a second sheet causes a new Print_Titles built-in
                // name to be created
@@ -203,7 +203,7 @@ public final class TestXSSFWorkbook extends TestCase {
                XSSFName nr2 = nwb.getNameAt(1);
                
                assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
-               assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getReference());
+               assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
                
                
                nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
@@ -464,11 +464,11 @@ public final class TestXSSFWorkbook extends TestCase {
                assertEquals(0, workbook.getNumberOfNames());
                
                Name nameA = workbook.createName();
-               nameA.setReference("A2");
+               nameA.setRefersToFormula("A2");
                nameA.setNameName("ForA2");
                
                XSSFName nameB = workbook.createName();
-               nameB.setReference("B3");
+               nameB.setRefersToFormula("B3");
                nameB.setNameName("ForB3");
                nameB.setComment("B3 Comment");
                
@@ -476,11 +476,11 @@ public final class TestXSSFWorkbook extends TestCase {
                workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
                
                assertEquals(2, workbook.getNumberOfNames());
-               assertEquals("A2", workbook.getNameAt(0).getReference());
+               assertEquals("A2", workbook.getNameAt(0).getRefersToFormula());
                assertEquals("ForA2", workbook.getNameAt(0).getNameName());
                assertNull(workbook.getNameAt(0).getComment());
                
-               assertEquals("B3", workbook.getNameAt(1).getReference());
+               assertEquals("B3", workbook.getNameAt(1).getRefersToFormula());
                assertEquals("ForB3", workbook.getNameAt(1).getNameName());
                assertEquals("B3 Comment", workbook.getNameAt(1).getComment());
                
@@ -493,11 +493,11 @@ public final class TestXSSFWorkbook extends TestCase {
                workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
 
                assertEquals(2, workbook.getNumberOfNames());
-               assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getReference());
+               assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getRefersToFormula());
                assertEquals("AllANumbers", workbook.getNameAt(0).getNameName());
                assertEquals("All the numbers in A", workbook.getNameAt(0).getComment());
                
-               assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getReference());
+               assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getRefersToFormula());
                assertEquals("AllBStrings", workbook.getNameAt(1).getNameName());
                assertEquals("All the strings in B", workbook.getNameAt(1).getComment());
                
@@ -507,11 +507,11 @@ public final class TestXSSFWorkbook extends TestCase {
                workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
                
                assertEquals(2, workbook.getNumberOfNames());
-               assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getReference());
+               assertEquals("Sheet1!$A$2:$A$7", workbook.getNameAt(0).getRefersToFormula());
                assertEquals("AllANumbers", workbook.getNameAt(0).getNameName());
                assertEquals("All the numbers in A", workbook.getNameAt(0).getComment());
                
-               assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getReference());
+               assertEquals("Sheet1!$B$2:$B$7", workbook.getNameAt(1).getRefersToFormula());
                assertEquals("BStringsFun", workbook.getNameAt(1).getNameName());
                assertEquals("All the strings in B", workbook.getNameAt(1).getComment());
        }
index b9e9315945b9902929f3134c224a91c601536310..fe248ca8b50f366bb76e044de4db32068ee86a03 100644 (file)
@@ -825,7 +825,7 @@ public final class TestFormulaParser extends TestCase {
                HSSFWorkbook wb = new HSSFWorkbook();
                HSSFSheet sheet = wb.createSheet("Sheet1");
                HSSFName name = wb.createName();
-               name.setFormula("Sheet1!B1");
+               name.setRefersToFormula("Sheet1!B1");
                name.setNameName("pfy1");
 
                Ptg[] ptgs;
index a54b619941d747d2039d38818b4f0b7e7c7e0735..77cf55b726265c105dec76f9da2f0f7abd86f8ed 100755 (executable)
@@ -76,9 +76,9 @@ public final class TestNameRecord extends TestCase {
                HSSFName name = wb.createName();
                wb.createSheet("Sheet1");
                name.setNameName("test");
-               name.setFormula("Sheet1!A1+Sheet1!A2");
-               assertEquals("Sheet1!A1+Sheet1!A2", name.getFormula());
-               name.setFormula("5*6");
-               assertEquals("5*6", name.getFormula());
+               name.setRefersToFormula("Sheet1!A1+Sheet1!A2");
+               assertEquals("Sheet1!A1+Sheet1!A2", name.getRefersToFormula());
+               name.setRefersToFormula("5*6");
+               assertEquals("5*6", name.getRefersToFormula());
        }
 }