From f12b4221149fa479415b95ddd32bcd2534771bba Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Wed, 11 Sep 2002 02:30:43 +0000 Subject: [PATCH] http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12349 PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352841 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/usermodel/HSSFDataFormat.java | 10 ++++++++++ .../org/apache/poi/hssf/usermodel/TestWorkbook.java | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java index ba514eb1ee..779dd0f1fa 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java @@ -62,6 +62,7 @@ package org.apache.poi.hssf.usermodel; import java.util.Vector; import java.util.List; import java.util.ListIterator; +import java.util.Iterator; import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.Record; @@ -133,6 +134,15 @@ public class HSSFDataFormat public HSSFDataFormat(Workbook workbook) { this.workbook = workbook; if (builtinFormats == null) populateBuiltinFormats(); + Iterator i = workbook.getFormats().iterator(); + while (i.hasNext()) { + FormatRecord r = (FormatRecord)i.next(); + if (formats.size() < r.getIndexCode() + 1) { + formats.setSize(r.getIndexCode() + 1); + } + formats.set(r.getIndexCode(), r.getFormatString()); + } + } private static synchronized void populateBuiltinFormats() diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java index 91edfffbc0..9b7e4b728d 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java @@ -249,12 +249,13 @@ public class TestWorkbook HSSFWorkbook workbook = new HSSFWorkbook(fs); HSSFSheet sheet = workbook.getSheetAt(0); HSSFDataFormat format = workbook.createDataFormat(); + HSSFCell cell = + sheet.getRow(( short ) 0).getCell(( short ) 0); - assertEquals(1.25, - sheet.getRow(( short ) 0).getCell(( short ) 0) - .getNumericCellValue(), 1e-10); + assertEquals(1.25,cell.getNumericCellValue(), 1e-10); + - assertEquals(format.getFormat("0.0"), 0xa4); + assertEquals(format.getFormat(cell.getCellStyle().getDataFormat()), "0.0"); stream.close(); } -- 2.39.5