Browse Source

fixed bug 46250

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1382494 13f79535-47bb-0310-9956-ffa450edef68
tags/3.10-beta1
Evgeniy Berlog 11 years ago
parent
commit
a0ad9be37d

+ 17
- 1
src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java View 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;
}
}

+ 4
- 2
src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java View 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());

+ 14
- 0
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java View 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);
}
}

BIN
test-data/spreadsheet/46250.xls View File


Loading…
Cancel
Save