From 48168d4301ceabcd7145488d58ed98614cf1effb Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 18 Jul 2008 18:40:11 +0000 Subject: [PATCH] Patch from bug #45414 - Don't add too many UncalcedRecords to sheets with charts in them git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@677995 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + src/java/org/apache/poi/hssf/model/Sheet.java | 23 +++++++++++-------- .../apache/poi/hssf/usermodel/TestBugs.java | 20 ++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index caa238df59..9933efbf1f 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45414 - Don't add too many UncalcedRecords to sheets with charts in them 45398 - Support detecting date formats containing "am/pm" as date times 45410 - Removed dependency from contrib on commons beanutils,collections and lang New helper, HSSFOptimiser, which handles removing duplicated font and style records, to avoid going over the limits in Excel diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 798d358294..09949e470b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45414 - Don't add too many UncalcedRecords to sheets with charts in them 45398 - Support detecting date formats containing "am/pm" as date times 45410 - Removed dependency from contrib on commons beanutils,collections and lang New helper, HSSFOptimiser, which handles removing duplicated font and style records, to avoid going over the limits in Excel diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index b95ad6bba3..cbbe663b1d 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -827,16 +827,21 @@ public final class Sheet implements Model { // If the BOF record was just serialized then add the IndexRecord if (record.getSid() == BOFRecord.sid) { - // Add an optional UncalcedRecord - if (_isUncalced) { - UncalcedRecord rec = new UncalcedRecord(); - pos += rec.serialize(pos, data); - } - //Can there be more than one BOF for a sheet? If not then we can - //remove this guard. So be safe it is left here. - if (rows != null && !haveSerializedIndex) { + if (!haveSerializedIndex) { haveSerializedIndex = true; - pos += serializeIndexRecord(k, pos, data); + // Add an optional UncalcedRecord. However, we should add + // it in only the once, after the sheet's own BOFRecord. + // If there are diagrams, they have their own BOFRecords, + // and one shouldn't go in after that! + if (_isUncalced) { + UncalcedRecord rec = new UncalcedRecord(); + pos += rec.serialize(pos, data); + } + //Can there be more than one BOF for a sheet? If not then we can + //remove this guard. So be safe it is left here. + if (rows != null) { + pos += serializeIndexRecord(k, pos, data); + } } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 6e92f6e3de..fe201068de 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1362,4 +1362,24 @@ public final class TestBugs extends TestCase { HSSFSheet sh = wb.getSheetAt(0); for(short i=0; i < 30; i++) sh.autoSizeColumn(i); } + + /** + * We used to add too many UncalcRecords to sheets + * with diagrams on. Don't any more + */ + public void test45414() throws Exception { + HSSFWorkbook wb = openSample("WithThreeCharts.xls"); + wb.getSheetAt(0).setForceFormulaRecalculation(true); + wb.getSheetAt(1).setForceFormulaRecalculation(false); + wb.getSheetAt(2).setForceFormulaRecalculation(true); + + // Write out and back in again + // This used to break + HSSFWorkbook nwb = writeOutAndReadBack(wb); + + // Check now set as it should be + assertTrue(nwb.getSheetAt(0).getForceFormulaRecalculation()); + assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation()); + assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation()); + } } -- 2.39.5