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()));
}
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;
+ }
}
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());
+ }
}
/**
@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());
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);
+ }
}