]> source.dussan.org Git - poi.git/commitdiff
fixed bug 46250
authorEvgeniy Berlog <berlog@apache.org>
Sun, 9 Sep 2012 13:21:38 +0000 (13:21 +0000)
committerEvgeniy Berlog <berlog@apache.org>
Sun, 9 Sep 2012 13:21:38 +0000 (13:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1382494 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java
src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/46250.xls [new file with mode: 0644]

index ffbcec50e6bda88f09edd4f7641244c9855281c9..584f426fd3a83102f3279e99448220c4ea5599dd 100644 (file)
@@ -170,7 +170,8 @@ public class HSSFSimpleShape extends HSSFShape
         HSSFRichTextString rtr = (HSSFRichTextString) string;
         // If font is not set we must set the default one
         if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
-        _textObjectRecord.setStr(rtr);
+        TextObjectRecord txo = getOrCreateTextObjRecord();
+        txo.setStr(rtr);
         if (string.getString() != null){
             setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode()));
         }
@@ -234,4 +235,19 @@ public class HSSFSimpleShape extends HSSFShape
         EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
         spRecord.setShapeType((short) value);
     }
+    
+    private TextObjectRecord getOrCreateTextObjRecord(){
+        if (getTextObjectRecord() == null){
+            _textObjectRecord = createTextObjRecord();
+        }
+        EscherTextboxRecord escherTextbox = getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID);
+        if (null == escherTextbox){
+            escherTextbox = new EscherTextboxRecord();
+            escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
+            escherTextbox.setOptions((short) 0x0000);
+            getEscherContainer().addChildRecord(escherTextbox);
+            getPatriarch()._getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
+        }
+        return _textObjectRecord;
+    }
 }
index 4260ead63897e60bc383ff602207636435ac7407..dacdadd4f5e0db478671079d86aa3663b3bd185a 100644 (file)
@@ -133,7 +133,9 @@ public class HSSFTextbox extends HSSFSimpleShape {
     void afterInsert(HSSFPatriarch patriarch) {
         EscherAggregate agg = patriarch._getBoundAggregate();
         agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
-        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
+        if (getTextObjectRecord() != null){
+            agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
+        }
     }
 
     /**
@@ -231,7 +233,7 @@ public class HSSFTextbox extends HSSFSimpleShape {
 
     @Override
     protected HSSFShape cloneShape() {
-        TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
+        TextObjectRecord txo = getTextObjectRecord() == null ? null : (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
         EscherContainerRecord spContainer = new EscherContainerRecord();
         byte[] inSp = getEscherContainer().serialize();
         spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());
index 9c566b05b1a0c0c020f875493fc40ffcbfba1e07..8f4a4ec652dc0f6f4b98df3cf2319a229dcf6162 100644 (file)
@@ -2283,4 +2283,18 @@ if(1==2) {
         wb = writeOutAndReadBack((HSSFWorkbook) wb);
         assertEquals(wb.getAllPictures().size(), 1);
     }
+
+    public void test46250(){
+        Workbook wb = openSample("46250.xls");
+        Sheet sh = wb.getSheet("Template");
+        Sheet cSh = wb.cloneSheet(wb.getSheetIndex(sh));
+
+        HSSFPatriarch patriarch = (HSSFPatriarch) cSh.createDrawingPatriarch();
+        HSSFTextbox tb = (HSSFTextbox) patriarch.getChildren().get(2);
+
+        tb.setString(new HSSFRichTextString("POI test"));
+        tb.setAnchor(new HSSFClientAnchor(0,0,0,0,(short)0,0,(short)10,10));
+
+        wb = writeOutAndReadBack((HSSFWorkbook) wb);
+    }
 }
diff --git a/test-data/spreadsheet/46250.xls b/test-data/spreadsheet/46250.xls
new file mode 100644 (file)
index 0000000..7260bf3
Binary files /dev/null and b/test-data/spreadsheet/46250.xls differ