use of org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord in project poi by apache.
the class TestBugs method bug44840.
/**
* Problems with extracting check boxes from
* HSSFObjectData
*/
@Test(expected = FileNotFoundException.class)
public void bug44840() throws Exception {
HSSFWorkbook wb = openSample("WithCheckBoxes.xls");
// Take a look at the embedded objects
List<HSSFObjectData> objects = wb.getAllEmbeddedObjects();
assertEquals(1, objects.size());
HSSFObjectData obj = objects.get(0);
assertNotNull(obj);
// Peek inside the underlying record
EmbeddedObjectRefSubRecord rec = obj.findObjectRecord();
assertNotNull(rec);
// assertEquals(32, rec.field_1_stream_id_offset);
// WRONG!
assertEquals(0, rec.getStreamId().intValue());
assertEquals("Forms.CheckBox.1", rec.getOLEClassName());
assertEquals(12, rec.getObjectData().length);
// Doesn't have a directory
assertFalse(obj.hasDirectoryEntry());
assertNotNull(obj.getObjectData());
assertEquals(12, obj.getObjectData().length);
assertEquals("Forms.CheckBox.1", obj.getOLE2ClassName());
try {
obj.getDirectory();
} finally {
wb.close();
}
}
use of org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord in project poi by apache.
the class HSSFPatriarch method createObjectData.
@Override
public HSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
ObjRecord obj = new ObjRecord();
CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord();
ftCmo.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE);
// ftCmo.setObjectId(oleShape.getShapeId()); ... will be set by onCreate(...)
ftCmo.setLocked(true);
ftCmo.setPrintable(true);
ftCmo.setAutofill(true);
ftCmo.setAutoline(true);
ftCmo.setReserved1(0);
ftCmo.setReserved2(0);
ftCmo.setReserved3(0);
obj.addSubRecord(ftCmo);
// FtCf (pictFormat)
FtCfSubRecord ftCf = new FtCfSubRecord();
HSSFPictureData pictData = getSheet().getWorkbook().getAllPictures().get(pictureIndex - 1);
switch(pictData.getFormat()) {
case Workbook.PICTURE_TYPE_WMF:
case Workbook.PICTURE_TYPE_EMF:
// this needs patch #49658 to be applied to actually work
ftCf.setFlags(FtCfSubRecord.METAFILE_BIT);
break;
case Workbook.PICTURE_TYPE_DIB:
case Workbook.PICTURE_TYPE_PNG:
case Workbook.PICTURE_TYPE_JPEG:
case Workbook.PICTURE_TYPE_PICT:
ftCf.setFlags(FtCfSubRecord.BITMAP_BIT);
break;
default:
throw new IllegalStateException("Invalid picture type: " + pictData.getFormat());
}
obj.addSubRecord(ftCf);
// FtPioGrbit (pictFlags)
FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord();
ftPioGrbit.setFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true);
obj.addSubRecord(ftPioGrbit);
EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord();
ftPictFmla.setUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 });
ftPictFmla.setOleClassname("Paket");
ftPictFmla.setStorageId(storageId);
obj.addSubRecord(ftPictFmla);
obj.addSubRecord(new EndSubRecord());
String entryName = "MBD" + HexDump.toHex(storageId);
DirectoryEntry oleRoot;
try {
DirectoryNode dn = _sheet.getWorkbook().getDirectory();
if (dn == null) {
throw new FileNotFoundException();
}
oleRoot = (DirectoryEntry) dn.getEntry(entryName);
} catch (FileNotFoundException e) {
throw new IllegalStateException("trying to add ole shape without actually adding data first - use HSSFWorkbook.addOlePackage first", e);
}
// create picture shape, which need to be minimal modified for oleshapes
HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor) anchor);
shape.setPictureIndex(pictureIndex);
EscherContainerRecord spContainer = shape.getEscherContainer();
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
spRecord.setFlags(spRecord.getFlags() | EscherSpRecord.FLAG_OLESHAPE);
HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot);
addShape(oleShape);
onCreate(oleShape);
return oleShape;
}
Aggregations