poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1642497 - in /poi/trunk/src/java/org/apache/poi/hssf: extractor/OldExcelExtractor.java record/FormulaRecord.java record/OldFormulaRecord.java
Date Sun, 30 Nov 2014 01:30:43 GMT
Author: nick
Date: Sun Nov 30 01:30:43 2014
New Revision: 1642497

URL: http://svn.apache.org/r1642497
Log:
Formula values for Excel 4 extractor, for TIKA-1490

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
    poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1642497&r1=1642496&r2=1642497&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Sun Nov 30 01:30:43
2014
@@ -22,7 +22,6 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.hssf.record.NumberRecord;
 import org.apache.poi.hssf.record.OldFormulaRecord;
 import org.apache.poi.hssf.record.OldLabelRecord;
@@ -42,7 +41,6 @@ import org.apache.poi.ss.usermodel.Cell;
  */
 public class OldExcelExtractor {
     private InputStream input;
-    private boolean _includeSheetNames = true;
 
     public OldExcelExtractor(InputStream input) {
         this.input = input;
@@ -62,13 +60,6 @@ public class OldExcelExtractor {
     }
 
     /**
-     * Should sheet names be included? Default is true
-     */
-    public void setIncludeSheetNames(boolean includeSheetNames) {
-        _includeSheetNames = includeSheetNames;
-    }
-
-    /**
      * Retrieves the text contents of the file, as best we can
      *  for these old file formats
      */
@@ -95,32 +86,35 @@ public class OldExcelExtractor {
                     text.append(sr.getString());
                     text.append('\n');
                     break;
-                // number - 5.71 - TODO Needs format strings
+                    
                 case NumberRecord.sid:
                     NumberRecord nr = new NumberRecord(ris);
-                    text.append(nr.getValue());
-                    text.append('\n');
+                    handleNumericCell(text, nr.getValue());
                     break;
                 case OldFormulaRecord.biff2_sid:
                 case OldFormulaRecord.biff3_sid:
                 case OldFormulaRecord.biff4_sid:
                     OldFormulaRecord fr = new OldFormulaRecord(ris);
-//                  if (fr.getCachedResultType() == Cell.CELL_TYPE_NUMERIC) {
-                        text.append(fr.getValue());
-                        text.append('\n');
-//                  }
+                    if (fr.getCachedResultType() == Cell.CELL_TYPE_NUMERIC) {
+                        handleNumericCell(text, fr.getValue());
+                    }
                     break;
                 case RKRecord.sid:
                     RKRecord rr = new RKRecord(ris);
-                    text.append(rr.getRKNumber());
-                    text.append('\n');
+                    handleNumericCell(text, rr.getRKNumber());
                     break;
+                    
                 default:
                     ris.readFully(new byte[ris.remaining()]);
-      //              text.append(" = " + ris.getSid() + " = \n");
             }
         }
 
         return text.toString();
     }
+    
+    protected void handleNumericCell(StringBuffer text, double value) {
+        // TODO Need to fetch / use format strings
+        text.append(value);
+        text.append('\n');
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=1642497&r1=1642496&r2=1642497&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Sun Nov 30 01:30:43 2014
@@ -47,7 +47,7 @@ public final class FormulaRecord extends
 	 * Excel encodes the same 8 bytes that would be field_4_value with various NaN
 	 * values that are decoded/encoded by this class. 
 	 */
-	private static final class SpecialCachedValue {
+	static final class SpecialCachedValue {
 		/** deliberately chosen by Excel in order to encode other values within Double NaNs */
 		private static final long BIT_MARKER = 0xFFFF000000000000L;
 		private static final int VARIABLE_DATA_LENGTH = 6;

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java?rev=1642497&r1=1642496&r2=1642497&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/OldFormulaRecord.java Sun Nov 30 01:30:43
2014
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.record;
 
+import org.apache.poi.hssf.record.FormulaRecord.SpecialCachedValue;
+import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.ss.formula.Formula;
 import org.apache.poi.ss.formula.ptg.Ptg;
 
@@ -30,6 +32,7 @@ public final class OldFormulaRecord exte
     public final static short biff4_sid = 0x0406;
     public final static short biff5_sid = 0x0006;
 
+    private SpecialCachedValue specialCachedValue;
     private double  field_4_value;
     private short   field_5_options;
     private Formula field_6_parsed_expr;
@@ -37,8 +40,15 @@ public final class OldFormulaRecord exte
     public OldFormulaRecord(RecordInputStream ris) {
         super(ris, ris.getSid() == biff2_sid);
 
-        // TODO Handle special cached values, for Biff 3+
-        field_4_value = ris.readDouble();
+        if (isBiff2()) {
+            field_4_value = ris.readDouble();
+        } else {
+            long valueLongBits  = ris.readLong();
+            specialCachedValue = SpecialCachedValue.create(valueLongBits);
+            if (specialCachedValue == null) {
+                field_4_value = Double.longBitsToDouble(valueLongBits);
+            }
+        }
 
         if (isBiff2()) {
             field_5_options = (short)ris.readUByte();
@@ -51,6 +61,20 @@ public final class OldFormulaRecord exte
         field_6_parsed_expr = Formula.read(expression_len, ris, nBytesAvailable);
     }
 
+    public int getCachedResultType() {
+        if (specialCachedValue == null) {
+            return HSSFCell.CELL_TYPE_NUMERIC;
+        }
+        return specialCachedValue.getValueType();
+    }
+    
+    public boolean getCachedBooleanValue() {
+        return specialCachedValue.getBooleanValue();
+    }
+    public int getCachedErrorValue() {
+        return specialCachedValue.getErrorValue();
+    }
+    
     /**
      * get the calculated value of the formula
      *



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message