use of org.apache.poi.hssf.record.DrawingGroupRecord in project poi by apache.
the class InternalWorkbook method createDrawingGroup.
/**
* Creates a primary drawing group record. If it already
* exists then it's modified.
*/
public void createDrawingGroup() {
if (drawingManager == null) {
EscherContainerRecord dggContainer = new EscherContainerRecord();
EscherDggRecord dgg = new EscherDggRecord();
EscherOptRecord opt = new EscherOptRecord();
EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();
dggContainer.setRecordId((short) 0xF000);
dggContainer.setOptions((short) 0x000F);
dgg.setRecordId(EscherDggRecord.RECORD_ID);
dgg.setOptions((short) 0x0000);
dgg.setShapeIdMax(1024);
dgg.setNumShapesSaved(0);
dgg.setDrawingsSaved(0);
dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {});
drawingManager = new DrawingManager2(dgg);
EscherContainerRecord bstoreContainer = null;
if (!escherBSERecords.isEmpty()) {
bstoreContainer = new EscherContainerRecord();
bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
for (EscherRecord escherRecord : escherBSERecords) {
bstoreContainer.addChildRecord(escherRecord);
}
}
opt.setRecordId((short) 0xF00B);
opt.setOptions((short) 0x0033);
opt.addEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296));
opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 0x08000041));
opt.addEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, 134217792));
splitMenuColors.setRecordId((short) 0xF11E);
splitMenuColors.setOptions((short) 0x0040);
splitMenuColors.setColor1(0x0800000D);
splitMenuColors.setColor2(0x0800000C);
splitMenuColors.setColor3(0x08000017);
splitMenuColors.setColor4(0x100000F7);
dggContainer.addChildRecord(dgg);
if (bstoreContainer != null) {
dggContainer.addChildRecord(bstoreContainer);
}
dggContainer.addChildRecord(opt);
dggContainer.addChildRecord(splitMenuColors);
int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
if (dgLoc == -1) {
DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer);
int loc = findFirstRecordLocBySid(CountryRecord.sid);
getRecords().add(loc + 1, drawingGroup);
} else {
DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
drawingGroup.addEscherRecord(dggContainer);
getRecords().set(dgLoc, drawingGroup);
}
}
}
use of org.apache.poi.hssf.record.DrawingGroupRecord in project poi by apache.
the class InternalWorkbook method findDrawingGroup.
/**
* Finds the primary drawing group, if one already exists
*
* @return the primary drawing group
*/
public DrawingManager2 findDrawingGroup() {
if (drawingManager != null) {
// We already have it!
return drawingManager;
}
// Need to find a DrawingGroupRecord that contains a EscherDggRecord
for (Record r : records) {
if (!(r instanceof DrawingGroupRecord)) {
continue;
}
DrawingGroupRecord dg = (DrawingGroupRecord) r;
dg.processChildRecords();
drawingManager = findDrawingManager(dg, escherBSERecords);
if (drawingManager != null) {
return drawingManager;
}
}
// TODO: we've already scanned the records, why should this work any better now?
// Look for the DrawingGroup record
DrawingGroupRecord dg = (DrawingGroupRecord) findFirstRecordBySid(DrawingGroupRecord.sid);
drawingManager = findDrawingManager(dg, escherBSERecords);
return drawingManager;
}
use of org.apache.poi.hssf.record.DrawingGroupRecord in project poi by apache.
the class InternalWorkbook method addBSERecord.
public int addBSERecord(EscherBSERecord e) {
createDrawingGroup();
// maybe we don't need that as an instance variable anymore
escherBSERecords.add(e);
int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
DrawingGroupRecord drawingGroup = (DrawingGroupRecord) getRecords().get(dgLoc);
EscherContainerRecord dggContainer = (EscherContainerRecord) drawingGroup.getEscherRecord(0);
EscherContainerRecord bstoreContainer;
if (dggContainer.getChild(1).getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
bstoreContainer = (EscherContainerRecord) dggContainer.getChild(1);
} else {
bstoreContainer = new EscherContainerRecord();
bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
List<EscherRecord> childRecords = dggContainer.getChildRecords();
childRecords.add(1, bstoreContainer);
dggContainer.setChildRecords(childRecords);
}
bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
bstoreContainer.addChildRecord(e);
return escherBSERecords.size();
}
use of org.apache.poi.hssf.record.DrawingGroupRecord in project poi by apache.
the class BiffDrawingToXml method writeToFile.
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook(xlsWorkbook);
InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
StringBuilder builder = new StringBuilder();
builder.append("<workbook>\n");
String tab = "\t";
if (!excludeWorkbookRecords && r != null) {
r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
for (EscherRecord record : escherRecords) {
builder.append(record.toXml(tab));
}
}
List<Integer> sheets = getSheetsIndexes(params, workbook);
for (Integer i : sheets) {
HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
if (p != null) {
builder.append(tab).append("<sheet").append(i).append(">\n");
builder.append(p.getBoundAggregate().toXml(tab + "\t"));
builder.append(tab).append("</sheet").append(i).append(">\n");
}
}
builder.append("</workbook>\n");
fos.write(builder.toString().getBytes(StringUtil.UTF8));
fos.close();
workbook.close();
}
use of org.apache.poi.hssf.record.DrawingGroupRecord in project poi by apache.
the class HSSFWorkbook method dumpDrawingGroupRecords.
/**
* Spits out a list of all the drawing records in the workbook.
*/
public void dumpDrawingGroupRecords(boolean fat) {
DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid(DrawingGroupRecord.sid);
r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
for (EscherRecord escherRecord : escherRecords) {
if (fat) {
System.out.println(escherRecord);
} else {
escherRecord.display(w, 0);
}
}
w.flush();
}
Aggregations