poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1402186 - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/usermodel/ src/testcases/org/apache/poi/hssf/usermodel/ test-data/spreadsheet/
Date Thu, 25 Oct 2012 15:13:53 GMT
Author: yegor
Date: Thu Oct 25 15:13:53 2012
New Revision: 1402186

URL: http://svn.apache.org/viewvc?rev=1402186&view=rev
Log:
Bug #53404 - Fixed compatibility issue with modifying xls files created by POI-3.6 and earlier

Added:
    poi/trunk/test-data/spreadsheet/53404.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1402186&r1=1402185&r2=1402186&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Oct 25 15:13:53 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="add">53404 - Fixed compatibility bug with
modifying xls files created by POI-3.6 and earlier</action>
           <action dev="poi-developers" type="add">53979 - Support fetching properties
of Numbered Lists from PPT files</action>
           <action dev="poi-developers" type="add">53784 - Partial HSMF support for
fixed sized properties</action>
           <action dev="poi-developers" type="add">53943 - added method processSymbol()
to allow converting word symbols   </action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java?rev=1402186&r1=1402185&r2=1402186&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java Thu Oct 25 15:13:53
2012
@@ -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;

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1402186&r1=1402185&r2=1402186&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Thu Oct 25 15:13:53
2012
@@ -1241,8 +1241,10 @@ public final class HSSFWorkbook extends 
         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();

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1402186&r1=1402185&r2=1402186&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Thu Oct 25 15:13:53
2012
@@ -40,10 +40,7 @@ import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.util.TempFile;
 
 import java.io.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 /**
  * Testcases for bugs entered in bugzilla
@@ -2297,4 +2294,23 @@ if(1==2) {
 
         wb = writeOutAndReadBack((HSSFWorkbook) wb);
     }
+
+    public void test53404(){
+        Workbook wb = openSample("53404.xls");
+        Sheet sheet = wb.getSheet("test-sheet");
+        int rowCount = sheet.getLastRowNum() + 1;
+        int newRows = 5;
+        for (int r = rowCount; r < rowCount + newRows; r++) {
+            Row row = sheet.createRow((short) r);
+            row.createCell(0).setCellValue(1.03 * (r + 7));
+            row.createCell(1).setCellValue(new Date());
+            row.createCell(2).setCellValue(Calendar.getInstance());
+            row.createCell(3).setCellValue(String.format("row:%d/col:%d", r, 3));
+            row.createCell(4).setCellValue(true);
+            row.createCell(5).setCellType(Cell.CELL_TYPE_ERROR);
+            row.createCell(6).setCellValue("added cells.");
+        }
+
+        wb = writeOutAndReadBack((HSSFWorkbook) wb);
+    }
 }

Added: poi/trunk/test-data/spreadsheet/53404.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/53404.xls?rev=1402186&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/53404.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message