]> source.dussan.org Git - poi.git/commitdiff
62815 -- some numeric values not correctly extracted from xlsb
authorTim Allison <tallison@apache.org>
Thu, 11 Oct 2018 14:14:07 +0000 (14:14 +0000)
committerTim Allison <tallison@apache.org>
Thu, 11 Oct 2018 14:14:07 +0000 (14:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1843553 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java
src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFBEventBasedExcelExtractor.java
test-data/spreadsheet/62815.xlsb [new file with mode: 0644]
test-data/spreadsheet/62815.xlsb.txt [new file with mode: 0644]

index fb3f433bd66542fc1d5fc2e15224ada7eeae79b5..726c2eeb897b58d2062b33866302d59a503d32d0 100644 (file)
@@ -302,9 +302,8 @@ public class XSSFBSheetHandler extends XSSFBParser {
     }
 
     private double rkNumber(byte[] data, int offset) {
-        //see 2.5.122 for this abomination
+        //see 2.5.122
         byte b0 = data[offset];
-        String s = Integer.toString(b0, 2);
         boolean numDivBy100 = ((b0 & 1) == 1); // else as is
         boolean floatingPoint = ((b0 >> 1 & 1) == 0); // else signed integer
 
@@ -320,7 +319,8 @@ public class XSSFBSheetHandler extends XSSFBParser {
         if (floatingPoint) {
             d = LittleEndian.getDouble(rkBuffer);
         } else {
-            d = LittleEndian.getInt(rkBuffer);
+            int rawInt = LittleEndian.getInt(rkBuffer, 4);
+            d = rawInt >> 2;//divide by 4/shift bits coz 30 bit int, not 32
         }
         d = (numDivBy100) ? d/100 : d;
         return d;
index 4fd9a5c1d78567287ea82bf75a679ab8d6b7f0d5..e17387618874fe3d3a0195a20f6b6acd09f32d24 100644 (file)
@@ -26,6 +26,10 @@ import static org.junit.Assert.assertTrue;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.junit.Test;
 
+import java.io.BufferedReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
 /**
  * Tests for {@link XSSFBEventBasedExcelExtractor}
  */
@@ -110,4 +114,23 @@ public class TestXSSFBEventBasedExcelExtractor {
                 "This is an example spreadsheet created with Microsoft Excel 2007 Beta 2.");
     }
 
+    @Test
+    public void test62815() throws Exception {
+        //test file based on http://oss.sheetjs.com/test_files/RkNumber.xlsb
+        XSSFEventBasedExcelExtractor extractor = getExtractor("62815.xlsb");
+        extractor.setIncludeCellComments(true);
+        String[] rows = extractor.getText().split("[\r\n]+");
+        assertEquals(283, rows.length);
+        BufferedReader reader = Files.newBufferedReader(XSSFTestDataSamples.getSampleFile("62815.xlsb.txt").toPath(),
+                StandardCharsets.UTF_8);
+        String line = reader.readLine();
+        for (int i = 0; i < rows.length; i++) {
+            assertEquals(line, rows[i]);
+            line = reader.readLine();
+            while (line != null && line.startsWith("#")) {
+                line = reader.readLine();
+            }
+        }
+    }
+
 }
diff --git a/test-data/spreadsheet/62815.xlsb b/test-data/spreadsheet/62815.xlsb
new file mode 100644 (file)
index 0000000..66d8e65
Binary files /dev/null and b/test-data/spreadsheet/62815.xlsb differ
diff --git a/test-data/spreadsheet/62815.xlsb.txt b/test-data/spreadsheet/62815.xlsb.txt
new file mode 100644 (file)
index 0000000..94060e3
--- /dev/null
@@ -0,0 +1,284 @@
+RkNumber
+10000000
+1200455
+0.01
+12004.55
+-10000000
+-1200455
+-0.01
+-12004.55
+10268609
+1071427521
+-1071427521
+273214017855
+69942788570880
+17905353874145300
+17835411085574400
+273214017855
+273214017856
+273214017857
+273214017858
+273214017859
+273214017860
+273214017861
+273214017862
+273214017863
+273214017864
+273214017865
+273214017866
+273214017867
+273214017868
+273214017869
+273214017870
+273214017871
+273214017872
+273214017873
+273214017874
+273214017875
+273214017876
+273214017877
+273214017878
+273214017879
+273214017880
+273214017881
+273214017882
+273214017883
+273214017884
+273214017885
+273214017886
+273214017887
+273214017888
+273214017889
+273214017890
+273214017891
+273214017892
+273214017893
+273214017894
+273214017895
+273214017896
+273214017897
+273214017898
+273214017899
+273214017900
+273214017901
+273214017902
+273214017903
+273214017904
+273214017905
+273214017906
+273214017907
+273214017908
+273214017909
+273214017910
+273214017911
+273214017912
+273214017913
+273214017914
+273214017915
+273214017916
+273214017917
+273214017918
+273214017919
+273214017920
+273214017921
+273214017922
+273214017923
+273214017924
+273214017925
+273214017926
+273214017927
+273214017928
+273214017929
+273214017930
+273214017931
+273214017932
+273214017933
+273214017934
+273214017935
+273214017936
+273214017937
+273214017938
+273214017939
+273214017940
+273214017941
+273214017942
+273214017943
+273214017944
+273214017945
+273214017946
+273214017947
+273214017948
+273214017949
+273214017950
+273214017951
+273214017952
+273214017953
+273214017954
+273214017955
+273214017956
+273214017957
+273214017958
+273214017959
+273214017960
+273214017961
+273214017962
+273214017963
+273214017964
+273214017965
+273214017966
+273214017967
+273214017968
+273214017969
+273214017970
+273214017971
+273214017972
+273214017973
+273214017974
+273214017975
+273214017976
+273214017977
+273214017978
+273214017979
+273214017980
+273214017981
+273214017982
+273214017983
+273214017984
+273214017985
+273214017986
+273214017987
+273214017988
+273214017989
+273214017990
+273214017991
+273214017992
+273214017993
+273214017994
+273214017995
+273214017996
+273214017997
+273214017998
+273214017999
+273214018000
+273214018001
+273214018002
+273214018003
+273214018004
+273214018005
+273214018006
+273214018007
+273214018008
+273214018009
+273214018010
+273214018011
+273214018012
+273214018013
+273214018014
+273214018015
+273214018016
+273214018017
+273214018018
+273214018019
+273214018020
+273214018021
+273214018022
+273214018023
+273214018024
+273214018025
+273214018026
+273214018027
+273214018028
+273214018029
+273214018030
+273214018031
+273214018032
+273214018033
+273214018034
+273214018035
+273214018036
+273214018037
+273214018038
+273214018039
+273214018040
+273214018041
+273214018042
+273214018043
+273214018044
+273214018045
+273214018046
+273214018047
+273214018048
+273214018049
+273214018050
+273214018051
+273214018052
+273214018053
+273214018054
+273214018055
+273214018056
+273214018057
+273214018058
+273214018059
+273214018060
+273214018061
+273214018062
+273214018063
+273214018064
+273214018065
+273214018066
+273214018067
+273214018068
+273214018069
+273214018070
+273214018071
+273214018072
+273214018073
+273214018074
+273214018075
+273214018076
+273214018077
+273214018078
+273214018079
+273214018080
+273214018081
+273214018082
+273214018083
+273214018084
+273214018085
+273214018086
+273214018087
+273214018088
+273214018089
+273214018090
+273214018091
+273214018092
+273214018093
+273214018094
+273214018095
+273214018096
+273214018097
+273214018098
+273214018099
+273214018100
+273214018101
+273214018102
+273214018103
+273214018104
+273214018105
+273214018106
+273214018107
+273214018108
+273214018109
+273214018110
+273214018111
+273214018112
+273214018113
+273214018114
+273214018115
+910713.3937166670
+3.03571131238889
+0.000010119037707963000
+3.37E-11
+1.12E-16
+#excel doesn't display ...863, this was manually altered to get the test to work
+3.7477917436899863E-22