From 870c1b2cf567209a0c159415cefd89a1615c3e2c Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Thu, 11 Oct 2018 14:14:07 +0000 Subject: [PATCH] 62815 -- some numeric values not correctly extracted from xlsb git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1843553 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/binary/XSSFBSheetHandler.java | 6 +- .../TestXSSFBEventBasedExcelExtractor.java | 23 ++ test-data/spreadsheet/62815.xlsb | Bin 0 -> 10665 bytes test-data/spreadsheet/62815.xlsb.txt | 284 ++++++++++++++++++ 4 files changed, 310 insertions(+), 3 deletions(-) create mode 100644 test-data/spreadsheet/62815.xlsb create mode 100644 test-data/spreadsheet/62815.xlsb.txt diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java index fb3f433bd6..726c2eeb89 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java @@ -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; diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFBEventBasedExcelExtractor.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFBEventBasedExcelExtractor.java index 4fd9a5c1d7..e173876188 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFBEventBasedExcelExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFBEventBasedExcelExtractor.java @@ -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 index 0000000000000000000000000000000000000000..66d8e652b0832340befba4bbcffefafbad1921f3 GIT binary patch literal 10665 zcmeHNhhJ04_D={^s`TEgQlv+z0wRKh-UA3Ebm^f@Iw#*(Eoqef3XHKjfXs`eFq5p9V^P&_%~lyt51JW}eJHpgbC zgPm?yUq}z{g~2B=)BGDw2WQ)BNTX%SC*G-cxvI+LDJx$$t%oF$-n?KJM7pI*YJ4%1 zwh48^S*Z49W~9xDCbYc42l63ECiv{&eUM;J(c+EqR|*K9QuVsBkG^KFnlFgn4_IR@ zzkO}ZuL$u_t#`hpwTJl}(R~Lh8YsA=Do7-&k(>|1`Z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