From 0a6a844dda325ef03b108cac47917d56352e1ea7 Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Sun, 28 Apr 2002 00:44:40 +0000 Subject: [PATCH] Wow... Fixed sizing bug 8592 -- see bug for details. Basically we couldn't handle variable sized value records (formulas are the only one we do so far). Now we're a bit less efficient (reiterate through all at the end for size calculations), but it works and is probably more flexible. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352508 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/FormulaRecord.java | 4 ++-- .../aggregates/ValueRecordsAggregate.java | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index ea1b387c6..db6c28ed7 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -351,7 +351,7 @@ public class FormulaRecord int ptgSize = getTotalPtgSize(); LittleEndian.putShort(data, 0 + offset, sid); - LittleEndian.putShort(data, 2 + offset, ( short ) (24 + ptgSize)); + LittleEndian.putShort(data, 2 + offset, ( short ) (22 + ptgSize)); LittleEndian.putShort(data, 4 + offset, getRow()); LittleEndian.putShort(data, 6 + offset, getColumn()); LittleEndian.putShort(data, 8 + offset, getXFIndex()); @@ -371,7 +371,7 @@ public class FormulaRecord int retval =0; if (EXPERIMENTAL_FORMULA_SUPPORT_ENABLED) { - retval = getTotalPtgSize() + 28; + retval = getTotalPtgSize() + 26; } else { retval =all_data.length; } diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java index e450befeb..c949e6fc5 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java @@ -78,7 +78,7 @@ public class ValueRecordsAggregate int firstcell = -1; int lastcell = -1; TreeMap records = null; - int size = 0; +// int size = 0; /** Creates a new instance of ValueRecordsAggregate */ @@ -89,7 +89,7 @@ public class ValueRecordsAggregate public void insertCell(CellValueRecordInterface cell) { - if (records.get(cell) == null) +/* if (records.get(cell) == null) { size += (( Record ) cell).getRecordSize(); } @@ -97,7 +97,7 @@ public class ValueRecordsAggregate { size += (( Record ) cell).getRecordSize() - (( Record ) records.get(cell)).getRecordSize(); - } + }*/ // XYLocator xy = new XYLocator(cell.getRow(), cell.getColumn()); records.put(cell, cell); @@ -113,7 +113,7 @@ public class ValueRecordsAggregate public void removeCell(CellValueRecordInterface cell) { - size -= (( Record ) cell).getRecordSize(); + // size -= (( Record ) cell).getRecordSize(); // XYLocator xy = new XYLocator(cell.getRow(), cell.getColumn()); records.remove(cell); @@ -209,9 +209,17 @@ public class ValueRecordsAggregate return sid; } - public int getRecordSize() - { + public int getRecordSize() { + + int size = 0; + Iterator irecs = records.values().iterator(); + + while (irecs.hasNext()) { + size += (( Record ) irecs.next()).getRecordSize(); + } + return size; +// return size; } public Iterator getIterator()