avik        2002/08/03 11:16:54

  Modified:    src/java/org/apache/poi/hssf/model FormulaParser.java
               src/java/org/apache/poi/hssf/record/formula StringPtg.java
               src/testcases/org/apache/poi/hssf/usermodel
                        TestFormulas.java
  Added:       src/testcases/org/apache/poi/hssf/data StringFormulas.xls
  Log:
  writing string formulas now work
  
  Revision  Changes    Path
  1.3       +15 -2     
jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java
  
  Index: FormulaParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/FormulaParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormulaParser.java        15 Jul 2002 02:06:22 -0000      1.2
  +++ FormulaParser.java        3 Aug 2002 18:16:54 -0000       1.3
  @@ -210,7 +210,6 @@
           }
       }
       
  -    
       /** Get an Identifier */
       private String GetName() {
           StringBuffer Token = new StringBuffer();
  @@ -225,6 +224,20 @@
           return Token.toString();
       }
       
  +    /**Get an Identifier AS IS, without stripping white spaces or 
  +       converting to uppercase; used for literals */
  +    private String GetNameAsIs() {
  +        StringBuffer Token = new StringBuffer();
  +        if (!IsAlpha(Look)) {
  +            Expected("Name");
  +        }
  +        while (IsAlNum(Look) || IsWhite(Look)) {
  +            Token = Token.append(Look);
  +            GetChar();
  +        }
  +        return Token.toString();
  +    }
  +    
       
       /** Get a Number */
       private String GetNum() {
  @@ -355,7 +368,7 @@
       
       private void StringLiteral() {
           Match('"');
  -        String name= GetName();
  +        String name= GetNameAsIs();
           Match('"');
           tokens.add(new StringPtg(name));
       }
  
  
  
  1.4       +1 -1      
jakarta-poi/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
  
  Index: StringPtg.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/StringPtg.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringPtg.java    15 Jul 2002 00:14:39 -0000      1.3
  +++ StringPtg.java    3 Aug 2002 18:16:54 -0000       1.4
  @@ -114,7 +114,7 @@
   
       public String toFormulaString(SheetReferences refs)
       {
  -        return getValue();
  +        return "\""+getValue()+"\"";
       }
       public byte getDefaultOperandClass() {
          return Ptg.CLASS_VALUE;
  
  
  
  1.1                  
jakarta-poi/src/testcases/org/apache/poi/hssf/data/StringFormulas.xls
  
        <<Binary file>>
  
  
  1.22      +34 -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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- TestFormulas.java 26 Jun 2002 18:05:40 -0000      1.21
  +++ TestFormulas.java 3 Aug 2002 18:16:54 -0000       1.22
  @@ -824,6 +824,40 @@
               out.close();
               assertTrue("file exists",file.exists());
       }
  +    
  +    public void testStringFormulas()
  +        throws java.io.IOException
  +    {
  +        String readFilename = System.getProperty("HSSF.testdata.path");
  +
  +            File file = File.createTempFile("testStringFormula",".xls");
  +            FileOutputStream out    = new FileOutputStream(file);
  +            HSSFWorkbook     wb     = new HSSFWorkbook();
  +            HSSFSheet        s      = wb.createSheet("A");
  +            HSSFRow          r      = null;
  +            HSSFCell         c      = null;
  +            r = s.createRow((short)0);
  +            c=r.createCell((short)1); c.setCellFormula("UPPER(\"abc\")");
  +            c=r.createCell((short)2); c.setCellFormula("LOWER(\"ABC\")");
  +            c=r.createCell((short)3); c.setCellFormula("CONCATENATE(\" my \",\" 
name \")");
  +            
  +            wb.write(out);
  +            out.close();
  +            
  +             assertTrue("file exists",file.exists());
  +            
  +            FileInputStream in = new 
FileInputStream(readFilename+File.separator+"StringFormulas.xls");
  +            wb = new HSSFWorkbook(in);
  +            s = wb.getSheetAt(0);
  +            r = s.getRow(0);
  +            c = r.getCell((short)0);
  +            assertTrue("expected: UPPER(\"xyz\") got "+c.getCellFormula(), 
("UPPER(\"xyz\")").equals(c.getCellFormula()));
  +            //c = r.getCell((short)1);
  +            //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), 
("A!A1+A!B1").equals(c.getCellFormula()));
  +            in.close(); 
  +    }
  +    
  +    
       public static void main(String [] args) {
           System.out
           .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");
  
  
  

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

Reply via email to