From 925f4b85adbf04581fc309e2bcf1f6435edcf445 Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Thu, 23 Mar 2017 16:31:42 +0000 Subject: [PATCH] Bug 60906 -- fix style index git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1788282 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xssf/binary/XSSFBSheetHandler.java | 3 ++- .../org/apache/poi/xssf/binary/XSSFBStylesTable.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) 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 803306d40..5fd6d24e5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java @@ -192,7 +192,8 @@ public class XSSFBSheetHandler extends XSSFBParser { beforeCellValue(data); double val = rkNumber(data, XSSFBCellHeader.length); String formatString = styles.getNumberFormatString(cellBuffer.getStyleIdx()); - String formattedVal = dataFormatter.formatRawCellContents(val, cellBuffer.getStyleIdx(), formatString); + short styleIndex = styles.getNumberFormatIndex(cellBuffer.getStyleIdx()); + String formattedVal = dataFormatter.formatRawCellContents(val, styleIndex, formatString); handleCellValue(formattedVal); } diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBStylesTable.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBStylesTable.java index 10f3412a1..583c9fcec 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBStylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBStylesTable.java @@ -48,11 +48,16 @@ public class XSSFBStylesTable extends XSSFBParser { } String getNumberFormatString(int idx) { - if (numberFormats.containsKey(styleIds.get((short)idx))) { - return numberFormats.get(styleIds.get((short)idx)); + short numberFormatIdx = getNumberFormatIndex(idx); + if (numberFormats.containsKey(numberFormatIdx)) { + return numberFormats.get(numberFormatIdx); } - return BuiltinFormats.getBuiltinFormat(styleIds.get((short)idx)); + return BuiltinFormats.getBuiltinFormat(numberFormatIdx); + } + + short getNumberFormatIndex(int idx) { + return styleIds.get(idx); } @Override