fixed bug 46250

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1382494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Evgeniy Berlog 2012-09-09 13:21:38 +00:00
parent 881e7df713
commit c7c1fd596a
4 changed files with 35 additions and 3 deletions

View File

@ -170,7 +170,8 @@ public class HSSFSimpleShape extends HSSFShape
HSSFRichTextString rtr = (HSSFRichTextString) string; HSSFRichTextString rtr = (HSSFRichTextString) string;
// If font is not set we must set the default one // If font is not set we must set the default one
if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0); if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0);
_textObjectRecord.setStr(rtr); TextObjectRecord txo = getOrCreateTextObjRecord();
txo.setStr(rtr);
if (string.getString() != null){ if (string.getString() != null){
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode())); 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); EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
spRecord.setShapeType((short) value); 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;
}
} }

View File

@ -133,7 +133,9 @@ public class HSSFTextbox extends HSSFSimpleShape {
void afterInsert(HSSFPatriarch patriarch) { void afterInsert(HSSFPatriarch patriarch) {
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch._getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); 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 @Override
protected HSSFShape cloneShape() { protected HSSFShape cloneShape() {
TextObjectRecord txo = (TextObjectRecord) getTextObjectRecord().cloneViaReserialise(); TextObjectRecord txo = getTextObjectRecord() == null ? null : (TextObjectRecord) getTextObjectRecord().cloneViaReserialise();
EscherContainerRecord spContainer = new EscherContainerRecord(); EscherContainerRecord spContainer = new EscherContainerRecord();
byte[] inSp = getEscherContainer().serialize(); byte[] inSp = getEscherContainer().serialize();
spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory()); spContainer.fillFields(inSp, 0, new DefaultEscherRecordFactory());

View File

@ -2283,4 +2283,18 @@ if(1==2) {
wb = writeOutAndReadBack((HSSFWorkbook) wb); wb = writeOutAndReadBack((HSSFWorkbook) wb);
assertEquals(wb.getAllPictures().size(), 1); 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);
}
} }

Binary file not shown.