diff options
author | Yegor Kozlov <yegor@apache.org> | 2012-10-25 15:13:53 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2012-10-25 15:13:53 +0000 |
commit | 146345aef8e7cc3f0e6a64e08c6174a74424b93c (patch) | |
tree | 1979a52da2b70de0c2545f5df94a0633e7ae7ac4 /src/java/org/apache | |
parent | b128eeacc8b7544203637164c4ff3451729e8fb3 (diff) | |
download | poi-146345aef8e7cc3f0e6a64e08c6174a74424b93c.tar.gz poi-146345aef8e7cc3f0e6a64e08c6174a74424b93c.zip |
Bug #53404 - Fixed compatibility issue with modifying xls files created by POI-3.6 and earlier
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1402186 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/hssf/model/InternalWorkbook.java | 31 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java | 2 |
2 files changed, 23 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java index 88b9d63ef5..a989c32b98 100644 --- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -740,15 +740,6 @@ public final class InternalWorkbook { boundsheets.add(bsr); getOrCreateLinkTable().checkExternSheet(sheetnum); fixTabIdRecord(); - } else { - // Ensure we have enough tab IDs - // Can be a few short if new sheets were added - if(records.getTabpos() > 0) { - TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos()); - if(tir._tabids.length < boundsheets.size()) { - fixTabIdRecord(); - } - } } } @@ -787,15 +778,19 @@ public final class InternalWorkbook { /** * make the tabid record look like the current situation. * + * @return number of bytes written in the TabIdRecord */ - private void fixTabIdRecord() { + private int fixTabIdRecord() { TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos()); + int sz = tir.getRecordSize(); short[] tia = new short[ boundsheets.size() ]; for (short k = 0; k < tia.length; k++) { tia[ k ] = k; } tir.setTabIdArray(tia); + return tir.getRecordSize() - sz; + } /** @@ -1066,6 +1061,22 @@ public final class InternalWorkbook { return pos; } + /** + * Perform any work necessary before the workbook is about to be serialized. + * + * Include in it ant code that modifies the workbook record stream and affects its size. + */ + public void preSerialize(){ + // Ensure we have enough tab IDs + // Can be a few short if new sheets were added + if(records.getTabpos() > 0) { + TabIdRecord tir = ( TabIdRecord ) records.get(records.getTabpos()); + if(tir._tabids.length < boundsheets.size()) { + fixTabIdRecord(); + } + } + } + public int getSize() { int retval = 0; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index add83e7e68..c218775886 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1241,8 +1241,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss HSSFSheet[] sheets = getSheets(); int nSheets = sheets.length; + // before getting the workbook size we must tell the sheets that // serialization is about to occur. + workbook.preSerialize(); for (int i = 0; i < nSheets; i++) { sheets[i].getSheet().preSerialize(); sheets[i].preSerialize(); |