avik        2003/08/30 06:41:56

  Modified:    src/java/org/apache/poi/hssf/record/aggregates Tag:
                        REL_2_BRANCH FormulaRecordAggregate.java
               src/java/org/apache/poi/hssf/usermodel Tag: REL_2_BRANCH
                        HSSFCell.java
               src/testcases/org/apache/poi/hssf/usermodel Tag:
                        REL_2_BRANCH TestFormulas.java
  Log:
  access the result of string formulas
  getStringValue on HSSFCell now returns the formula result if it's a string formula
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.4.2.3   +5 -0      
jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
  
  Index: FormulaRecordAggregate.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java,v
  retrieving revision 1.4.2.2
  retrieving revision 1.4.2.3
  diff -u -r1.4.2.2 -r1.4.2.3
  --- FormulaRecordAggregate.java       25 Jul 2003 18:22:19 -0000      1.4.2.2
  +++ FormulaRecordAggregate.java       30 Aug 2003 13:41:56 -0000      1.4.2.3
  @@ -266,5 +266,10 @@
   
         return true;
      }
  +   
  +   public String getStringValue() {
  +        if(stringRecord==null) return null;
  +        return stringRecord.getString();
  +   }
   
   }
  
  
  
  No                   revision
  No                   revision
  1.22.2.2  +6 -0      jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
  
  Index: HSSFCell.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java,v
  retrieving revision 1.22.2.1
  retrieving revision 1.22.2.2
  diff -u -r1.22.2.1 -r1.22.2.2
  --- HSSFCell.java     23 Aug 2003 19:40:05 -0000      1.22.2.1
  +++ HSSFCell.java     30 Aug 2003 13:41:56 -0000      1.22.2.2
  @@ -326,6 +326,7 @@
   
               case CELL_TYPE_FORMULA :
                   cellValue = (( FormulaRecordAggregate ) 
cval).getFormulaRecord().getValue();
  +                stringValue=((FormulaRecordAggregate) cval).getStringValue();
                   break;
   
               case CELL_TYPE_BOOLEAN :
  @@ -797,6 +798,7 @@
       /**
        * get the value of the cell as a string - for numeric cells we throw an 
exception.
        * For blank cells we return an empty string.
  +     * For formulaCells that are not string Formulas, we return empty String
        */
   
       public String getStringCellValue()
  @@ -819,6 +821,10 @@
           {
               throw new NumberFormatException(
                   "You cannot get a string value from an error cell");
  +        }
  +        if (cellType == CELL_TYPE_FORMULA) 
  +        {
  +            if (stringValue==null) return "";
           }
           return stringValue;
       }
  
  
  
  No                   revision
  No                   revision
  1.30.2.2  +14 -0     
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
  
  Index: TestFormulas.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java,v
  retrieving revision 1.30.2.1
  retrieving revision 1.30.2.2
  diff -u -r1.30.2.1 -r1.30.2.2
  --- TestFormulas.java 23 Aug 2003 19:40:05 -0000      1.30.2.1
  +++ TestFormulas.java 30 Aug 2003 13:41:56 -0000      1.30.2.2
  @@ -1106,6 +1106,20 @@
           assertEquals(4d, d2.getNumericCellValue(), 1e-9);
       }
   
  +    public void testStringFormulaRead() throws IOException {
  +        File dir = new File(System.getProperty("HSSF.testdata.path"));
  +        File xls = new File(dir, "StringFormulas.xls");
  +        FileInputStream in = new FileInputStream(xls);
  +        HSSFWorkbook w;
  +        try {
  +            w = new HSSFWorkbook(in);
  +        } finally {
  +            in.close();
  +        }
  +        HSSFCell c = w.getSheetAt(0).getRow(0).getCell((short)0);
  +        assertEquals("String Cell value","XYZ",c.getStringCellValue());
  +    }
  +    
       public static void main(String [] args) {
           System.out
           .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to