]> source.dussan.org Git - poi.git/commitdiff
Fix bug #46664 - fix up Tab IDs when adding new sheets, so that print areas don't...
authorNick Burch <nick@apache.org>
Wed, 9 Jun 2010 22:56:16 +0000 (22:56 +0000)
committerNick Burch <nick@apache.org>
Wed, 9 Jun 2010 22:56:16 +0000 (22:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@953180 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 45793d79616f9025397ecbdf99273fdb411fa22e..50e37663d6b9e92a7106b287719fc591f985838f 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46664 - fix up Tab IDs when adding new sheets, so that print areas don't end up invalid</action>
            <action dev="POI-DEVELOPERS" type="fix">45269 - improve replaceText on HWPF ranges</action>
            <action dev="POI-DEVELOPERS" type="fix">47815 - correct documentation on what happens when you request a String from a non-string Formula cell</action>
            <action dev="POI-DEVELOPERS" type="fix">49386 - avoid NPE when extracting OOXML file properties which are dates</action>
index c17a4d717305232297f933c9930a6743e1748e29..b1340f524b40a7cf7ca0f35bd8a786d7fc5807bc 100644 (file)
@@ -712,6 +712,15 @@ 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();
+              }
+           }
         }
     }
 
index 01510b087d8c96fcf81b5da88ef36d1b9e710b6e..e7e503adcb351997ce4d644e8fab993d9f8d35a5 100644 (file)
@@ -35,6 +35,8 @@ import org.apache.poi.hssf.model.InternalWorkbook;
 import org.apache.poi.hssf.record.CellValueRecordInterface;
 import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
 import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.TabIdRecord;
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.common.UnicodeString;
 import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
@@ -1589,6 +1591,48 @@ public final class TestBugs extends BaseTestBugzillaIssues {
        assertEquals(2, wb.getNumberOfSheets());
     }
     
+    /**
+     * Newly created sheets need to get a 
+     *  proper TabID, otherwise print setup
+     *  gets confused on them. 
+     */
+    public void test46664() throws Exception {
+       HSSFWorkbook wb = new HSSFWorkbook();
+       HSSFSheet sheet = wb.createSheet("new_sheet");
+       HSSFRow row = sheet.createRow((short)0);
+       row.createCell(0).setCellValue(new HSSFRichTextString("Column A"));
+       row.createCell(1).setCellValue(new HSSFRichTextString("Column B"));
+       row.createCell(2).setCellValue(new HSSFRichTextString("Column C"));
+       row.createCell(3).setCellValue(new HSSFRichTextString("Column D"));
+       row.createCell(4).setCellValue(new HSSFRichTextString("Column E"));
+       row.createCell(5).setCellValue(new HSSFRichTextString("Column F"));
+
+       //set print area from column a to column c (on first row)
+       wb.setPrintArea(
+               0, //sheet index
+               0, //start column
+               2, //end column
+               0, //start row
+               0  //end row
+       );
+       
+       wb = writeOutAndReadBack(wb);
+       
+       // Ensure the tab index
+       TabIdRecord tr = null;
+       for(Record r : wb.getWorkbook().getRecords()) {
+          if(r instanceof TabIdRecord) {
+             tr = (TabIdRecord)r;
+          }
+       }
+       assertNotNull(tr);
+       assertEquals(1, tr._tabids.length);
+       assertEquals(0, tr._tabids[0]);
+       
+       // Ensure the print setup
+       assertEquals("new_sheet!$A$1:$C$1", wb.getPrintArea(0));
+    }
+    
     /**
      * Problems with formula references to 
      *  sheets via URLs