poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r477928 - /jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
Date Tue, 21 Nov 2006 22:17:35 GMT
Author: amol
Date: Tue Nov 21 14:17:34 2006
New Revision: 477928

URL: http://svn.apache.org/viewvc?view=rev&rev=477928
Log:
removed use of deprecated calls to get the String value of a cell

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?view=diff&rev=477928&r1=477927&r2=477928
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
Tue Nov 21 14:17:34 2006
@@ -4,7 +4,6 @@
  */
 package org.apache.poi.hssf.usermodel;
 
-import java.io.FileInputStream;
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
 import java.util.Map;
@@ -75,7 +74,6 @@
 import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
 import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.util.CellReference;
 
 /**
  * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
@@ -90,8 +88,6 @@
 
     private static final Class[] VALUE_CONTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class };
 
-    private static final Class[] AREA_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class,
ValueEval[].class };
-
     private static final Class[] AREA3D_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class,
ValueEval[].class };
 
     private static final Class[] REFERENCE_CONSTRUCTOR_CLASS_ARRAY = new Class[] { Ptg.class,
ValueEval.class };
@@ -186,7 +182,7 @@
                 break;
             case HSSFCell.CELL_TYPE_STRING:
                 retval = new CellValue(HSSFCell.CELL_TYPE_STRING);
-                retval.setStringValue(cell.getStringCellValue());
+                retval.setRichTextStringValue(cell.getRichStringCellValue());
                 break;
             }
         }
@@ -221,7 +217,7 @@
                     cell.setCellValue(cv.getNumberValue());
                     break;
                 case HSSFCell.CELL_TYPE_STRING:
-                    cell.setCellValue(cv.getStringValue());
+                    cell.setCellValue(cv.getRichTextStringValue());
                     break;
                 case HSSFCell.CELL_TYPE_BLANK:
                     break;
@@ -333,7 +329,7 @@
                 HSSFSheet xsheet = workbook.getSheetAt(ptg.getExternSheetIndex());
                 HSSFRow row = sheet.getRow(rownum);
                 HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
-                pushRef3DEval(ptg, stack, cell, row, sheet, workbook);
+                pushRef3DEval(ptg, stack, cell, row, xsheet, workbook);
             }
             else if (ptgs[i] instanceof AreaPtg) {
                 AreaPtg ap = (AreaPtg) ptgs[i];
@@ -364,7 +360,7 @@
                     HSSFRow row = sheet.getRow(x);
                     for (short y = col0; row != null && y < col1 + 1; y++) {
                         values[(x - row0) * (col1 - col0 + 1) + (y - col0)] = 
-                            getEvalForCell(row.getCell(y), row, sheet, workbook);
+                            getEvalForCell(row.getCell(y), row, xsheet, workbook);
                     }
                 }
                 AreaEval ae = new Area3DEval(a3dp, values);
@@ -475,7 +471,7 @@
                 retval = new NumberEval(cell.getNumericCellValue());
                 break;
             case HSSFCell.CELL_TYPE_STRING:
-                retval = new StringEval(cell.getStringCellValue());
+                retval = new StringEval(cell.getRichStringCellValue().getString());
                 break;
             case HSSFCell.CELL_TYPE_FORMULA:
                 retval = internalEvaluate(cell, row, sheet, workbook);
@@ -511,7 +507,7 @@
                 stack.push(new Ref2DEval(ptg, new NumberEval(cell.getNumericCellValue()),
false));
                 break;
             case HSSFCell.CELL_TYPE_STRING:
-                stack.push(new Ref2DEval(ptg, new StringEval(cell.getStringCellValue()),
false));
+                stack.push(new Ref2DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()),
false));
                 break;
             case HSSFCell.CELL_TYPE_FORMULA:
                 stack.push(new Ref2DEval(ptg, internalEvaluate(cell, row, sheet, workbook),
true));
@@ -548,7 +544,7 @@
                 stack.push(new Ref3DEval(ptg, new NumberEval(cell.getNumericCellValue()),
false));
                 break;
             case HSSFCell.CELL_TYPE_STRING:
-                stack.push(new Ref3DEval(ptg, new StringEval(cell.getStringCellValue()),
false));
+                stack.push(new Ref3DEval(ptg, new StringEval(cell.getRichStringCellValue().getString()),
false));
                 break;
             case HSSFCell.CELL_TYPE_FORMULA:
                 stack.push(new Ref3DEval(ptg, internalEvaluate(cell, row, sheet, workbook),
true));
@@ -576,7 +572,7 @@
      */
     public static final class CellValue {
         private int cellType;
-        private String stringValue;
+        private HSSFRichTextString richTextStringValue;
         private double numberValue;
         private boolean booleanValue;
         private byte errorValue;
@@ -614,16 +610,20 @@
             this.numberValue = numberValue;
         }
         /**
-         * @return Returns the stringValue.
+         * @return Returns the stringValue. This method is deprecated, use
+         * getRichTextStringValue instead
+         * @deprecated
          */
         public String getStringValue() {
-            return stringValue;
+            return richTextStringValue.getString();
         }
         /**
-         * @param stringValue The stringValue to set.
+         * @param stringValue The stringValue to set. This method is deprecated, use
+         * getRichTextStringValue instead.
+         * @deprecated
          */
         public void setStringValue(String stringValue) {
-            this.stringValue = stringValue;
+            this.richTextStringValue = new HSSFRichTextString(stringValue);
         }
         /**
          * @return Returns the cellType.
@@ -643,30 +643,18 @@
         public void setErrorValue(byte errorValue) {
             this.errorValue = errorValue;
         }
-    }
-
-    /**
-     * Manual testing... needs "the" c:/temp/test1.xls file to be present.
-     * 
-     * @param args
-     * @throws Exception
-     */
-    public static void main(String[] args) throws Exception {
-        String FILE_NAME = "c:/temp/test1.xls";
-
-        FileInputStream fis = new FileInputStream(FILE_NAME);
-        HSSFWorkbook wb = new HSSFWorkbook(fis);
-        fis.close();
-        HSSFSheet sheet = wb.getSheetAt(0);
-        HSSFFormulaEvaluator instance = new HSSFFormulaEvaluator(sheet, wb);
-
-        for (int rn = 1, rnSize = 4; rn <= rnSize; rn++) {
-            HSSFRow row = sheet.getRow(rn);
-            for (int cn = 5, cnSize = 7; cn <= cnSize; cn++) {
-                HSSFCell cell = row.getCell((short) cn);
-                System.out.println(new CellReference(rn, cn).toString() + ": " + instance.evaluate(cell));
-            }
-        }
+        /**
+         * @return Returns the richTextStringValue.
+         */
+		public HSSFRichTextString getRichTextStringValue() {
+			return richTextStringValue;
+		}
+        /**
+         * @param richTextStringValue The richTextStringValue to set.
+         */
+		public void setRichTextStringValue(HSSFRichTextString richTextStringValue) {
+			this.richTextStringValue = richTextStringValue;
+		}
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message