poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r669140 - in /poi/trunk/src: java/org/apache/poi/hssf/model/Workbook.java testcases/org/apache/poi/hssf/data/30978-alt.xls testcases/org/apache/poi/hssf/usermodel/TestBugs.java
Date Wed, 18 Jun 2008 11:35:06 GMT
Author: nick
Date: Wed Jun 18 04:35:04 2008
New Revision: 669140

URL: http://svn.apache.org/viewvc?rev=669140&view=rev
Log:
A partial fix for bug #30978, but something still remains, which seems to be related to changing
the ptg

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/30978-alt.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java?rev=669140&r1=669139&r2=669140&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java Wed Jun 18 04:35:04 2008
@@ -604,8 +604,28 @@
             fixTabIdRecord();
         }
         
-        // If we decide that we need to fix up
-        //  NameRecords, do it here
+        // Within NameRecords, it's ok to have the formula
+        //  part point at deleted sheets. It's also ok to
+        //  have the ExternSheetNumber point at deleted
+        //  sheets. 
+        // However, the sheet index must be adjusted, or
+        //  excel will break. (Sheet index is either 0 for
+        //  global, or 1 based index to sheet)
+        int sheetNum1Based = sheetnum + 1;
+        for(int i=0; i<getNumNames(); i++) {
+        	NameRecord nr = getNameRecord(i);
+        	
+        	if(nr.getIndexToSheet() == sheetNum1Based) {
+        		// Excel re-writes these to point to no sheet
+        		nr.setEqualsToIndexToSheet((short)0);
+        	} else if(nr.getIndexToSheet() > sheetNum1Based) {
+        		// Bump down by one, so still points
+        		//  at the same sheet
+        		nr.setEqualsToIndexToSheet((short)(
+        				nr.getEqualsToIndexToSheet()-1
+        		));
+        	}
+        }
     }
 
     /**

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/30978-alt.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/30978-alt.xls?rev=669140&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/30978-alt.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

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=669140&r1=669139&r2=669140&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 Wed Jun 18 04:35:04
2008
@@ -28,7 +28,10 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
 import org.apache.poi.hssf.util.Region;
 import org.apache.poi.util.TempFile;
 
@@ -989,4 +992,63 @@
         	fail();
         } catch(FileNotFoundException e) {}
     }
+    
+    /**
+     * Test that we can delete sheets without
+     *  breaking the build in named ranges
+     *  used for printing stuff.
+     * Currently broken, as we change the Ptg
+     */
+    public void BROKENtest30978() throws Exception {
+        HSSFWorkbook wb = openSample("30978-alt.xls");
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(3, wb.getNumberOfSheets());
+        
+        // Check all names fit within range, and use
+        //  DeletedArea3DPtg
+        Workbook w = wb.getWorkbook();
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+        
+        
+        // Delete the 2nd sheet
+        wb.removeSheetAt(1);
+        
+        
+        // Re-check
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(2, wb.getNumberOfSheets());
+        
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+        
+        
+        // Save and re-load
+        wb = writeOutAndReadBack(wb);
+        w = wb.getWorkbook();
+        
+        assertEquals(1, wb.getNumberOfNames());
+        assertEquals(2, wb.getNumberOfSheets());
+        
+        for(int i=0; i<w.getNumNames(); i++) {
+        	NameRecord r = w.getNameRecord(i);
+        	assertTrue(r.getIndexToSheet() <= wb.getNumberOfSheets());
+        	
+        	List nd = r.getNameDefinition();
+        	assertEquals(1, nd.size());
+        	assertTrue(nd.get(0) instanceof DeletedArea3DPtg);
+        }
+    }
 }



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


Mime
View raw message