poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r693221 - in /poi/trunk/src: java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/data/ testcases/org/apache/poi/hssf/usermodel/
Date Mon, 08 Sep 2008 19:49:04 GMT
Author: josh
Date: Mon Sep  8 12:49:03 2008
New Revision: 693221

URL: http://svn.apache.org/viewvc?rev=693221&view=rev
Log:
Additional fix for 45720 - bug in HSSFWorkbook.findExistingBuiltinNameRecordIdx

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/testRRaC.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.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=693221&r1=693220&r2=693221&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 Mon Sep  8 12:49:03 2008
@@ -2466,6 +2466,10 @@
         int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
         if(aggLoc != -1) {
             EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
+            EscherContainerRecord escherContainer = agg.getEscherContainer();
+            if (escherContainer == null) {
+                return;
+            }
 
             EscherDggRecord dgg = drawingManager.getDgg();
 
@@ -2475,7 +2479,7 @@
             dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
 
             EscherDgRecord dg = null;
-            for(Iterator it = agg.getEscherContainer().getChildRecords().iterator(); it.hasNext();)
{
+            for(Iterator it = escherContainer.getChildRecords().iterator(); it.hasNext();)
{
                 Object er = it.next();
                 if(er instanceof EscherDgRecord) {
                     dg = (EscherDgRecord)er;

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java?rev=693221&r1=693220&r2=693221&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java Mon Sep  8 12:49:03 2008
@@ -82,8 +82,9 @@
 
 	private short             field_1_option_flag;
 	private byte              field_2_keyboard_shortcut;
-	private short             field_5_index_to_sheet;     // unused: see field_6
-	/** the one based sheet number.  Zero if this is a global name */
+	/** One-based extern index of sheet (resolved via LinkTable). Zero if this is a global name
 */
+	private short             field_5_externSheetIndex_plus1;
+	/** the one based sheet number.  */
 	private int               field_6_sheetNumber;
 	private boolean           field_11_nameIsMultibyte;
 	private byte              field_12_built_in_code;
@@ -144,7 +145,7 @@
 
 	/**
 	 * For named ranges, and built-in names
-	 * @return the 1-based sheet number.  Zero if this is a global name
+	 * @return the 1-based sheet number. 
 	 */
 	public int getSheetNumber()
 	{
@@ -384,7 +385,7 @@
 		LittleEndian.putByte(data, 7 + offset, getNameTextLength());
 		// Note -
 		LittleEndian.putUShort(data, 8 + offset, Ptg.getEncodedSizeWithoutArrayData(field_13_name_definition));
-		LittleEndian.putUShort(data, 10 + offset, field_5_index_to_sheet);
+		LittleEndian.putUShort(data, 10 + offset, field_5_externSheetIndex_plus1);
 		LittleEndian.putUShort(data, 12 + offset, field_6_sheetNumber);
 		LittleEndian.putByte(data, 14 + offset, field_7_length_custom_menu);
 		LittleEndian.putByte(data, 15 + offset, field_8_length_description_text);
@@ -557,7 +558,7 @@
 		field_2_keyboard_shortcut           = in.readByte();
 		int field_3_length_name_text        = in.readByte();
 		int field_4_length_name_definition  = in.readShort();
-		field_5_index_to_sheet              = in.readShort();
+		field_5_externSheetIndex_plus1      = in.readShort();
 		field_6_sheetNumber                 = in.readUShort();
 		int field_7_length_custom_menu      = in.readUByte();
 		int field_8_length_description_text = in.readUByte();
@@ -649,8 +650,8 @@
 		sb.append("    .option flags           = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
 		sb.append("    .keyboard shortcut      = ").append(HexDump.byteToHex(field_2_keyboard_shortcut)).append("\n");
 		sb.append("    .length of the name     = ").append(getNameTextLength()).append("\n");
-		sb.append("    .unused                 = ").append( field_5_index_to_sheet ).append("\n");
-		sb.append("    .index to sheet (1-based, 0=Global) = ").append( field_6_sheetNumber ).append("\n");
+		sb.append("    .extSheetIx(1-based, 0=Global)= ").append( field_5_externSheetIndex_plus1
).append("\n");
+		sb.append("    .sheetTabIx             = ").append(field_6_sheetNumber ).append("\n");
 		sb.append("    .Menu text length       = ").append(field_14_custom_menu_text.length()).append("\n");
 		sb.append("    .Description text length= ").append(field_15_description_text.length()).append("\n");
 		sb.append("    .Help topic text length = ").append(field_16_help_topic_text.length()).append("\n");

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=693221&r1=693220&r2=693221&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 Mon Sep  8 12:49:03
2008
@@ -1042,13 +1042,7 @@
             if (!r.isBuiltInName() || r.getBuiltInName() != builtinCode) {
                 continue;
             }
-            if(r.getSheetNumber() == 0) {
-                //ignore "GLOBAL" name records
-                continue;
-            }
-            int externIndex = r.getSheetNumber() -1;
-            int nameRecordSheetIndex = workbook.getSheetIndexFromExternSheetIndex(externIndex);
-            if (nameRecordSheetIndex == sheetIndex) {
+            if (r.getSheetNumber() -1 == sheetIndex) {
                 return defNameIndex;
             }
         }

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

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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=693221&r1=693220&r2=693221&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Mon Sep  8
12:49:03 2008
@@ -527,4 +527,33 @@
             }
         }
     }
+    
+    /**
+     * Test to make sure that NameRecord.getSheetNumber() is interpreted as a
+     * 1-based sheet tab index (not a 1-based extern sheet index)
+     */
+    public void testFindBuiltInNameRecord() {
+        // testRRaC has multiple (3) built-in name records
+        // The second print titles name record has getSheetNumber()==4
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls");
+        NameRecord nr;
+        assertEquals(3, wb.getWorkbook().getNumNames());
+        nr = wb.getWorkbook().getNameRecord(2);
+        // TODO - render full row and full column refs properly
+        assertEquals("Sheet2!$A$1:$IV$1", nr.getAreaReference(wb)); // 1:1
+        
+        try {
+            wb.setRepeatingRowsAndColumns(3, 4, 5, 8, 11);
+        } catch (RuntimeException e) {
+            if (e.getMessage().equals("Builtin (7) already exists for sheet (4)")) {
+                // there was a problem in the code which locates the existing print titles
name record 
+                throw new RuntimeException("Identified bug 45720b");
+            }
+            throw e;
+        }
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertEquals(3, wb.getWorkbook().getNumNames());
+        nr = wb.getWorkbook().getNameRecord(2);
+        assertEquals("Sheet2!E:F,Sheet2!$A$9:$IV$12", nr.getAreaReference(wb)); // E:F,9:12
+    }
 }



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


Mime
View raw message